using System;
using System.Reflection;
namespace Brass {
///
/// AppSigner class provides a wrapper around the Wappsign COM object.
///
class AppSigner {
private Type Wappsign;
private object WappsignObj;
private void CreateWappsignObject() {
this.Wappsign = Type.GetTypeFromProgID("Wappsign.Sign");
if (Wappsign == null) throw new Exception("Wappsign not found.");
this.WappsignObj = Activator.CreateInstance(Wappsign);
}
///
/// Create instance of the AppSigner class (wrapper around Wappsign COM object).
///
public AppSigner() {
CreateWappsignObject();
}
///
/// Create instance of the AppSigner class (wrapper around Wappsign COM object).
///
/// Wappsign mode flags.
public AppSigner(Mode mode) {
CreateWappsignObject();
this.Flags = mode;
}
///
/// Controls the way that Wappsign operates.
///
[Flags]
public enum Mode : int {
/// Generates the log file.
Verbose = 1,
/// Affects FormatOutput(). Appends .8xk.
Output83 = 2,
/// Affects FormatOutput(). Appends .73k.
Output73 = 4,
/// Will append .hex to the output file and only run the Fillapp.
FillOnly = 8,
/// Detects the target calculator type (83P/73).
DetectType = 4096
}
///
/// Mode flags for Wappsign's operation.
///
public Mode Flags {
get {
return (Mode)this.Wappsign.InvokeMember("Flags", BindingFlags.GetProperty, null, this.WappsignObj, null);
}
set {
this.Wappsign.InvokeMember("Flags", BindingFlags.SetProperty, null, this.WappsignObj, new object[] { value });
}
}
///
/// Signs an application.
///
/// Filename of Intel hex source file.
/// Filename of key.
/// Filename used for output.
/// 0 if signed correctly, otherwise an error code. Use GetErrorMessage() to retrieve the full text error message. If DetectType is used with the flags, then Wappsign detects target calculator type.
public int Sign(string hex, string key, string output) {
return (int)this.Wappsign.InvokeMember("Sign", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { hex, key, output });
}
///
/// Detects and retrieves the key file used by the application. Uses the search paths saved in the registry. These can be modified at run time using the directory functions.
///
/// Filename of the Intel hex source file.
/// A string with the full path name to the key file, otherwise "".
public string GetKeyFile(string hex) {
return (string)this.Wappsign.InvokeMember("GetKeyFile", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { hex });
}
///
/// Simply takes filename, removes the extension and adds either .8xk, 73k or .hex according to the Flags properties.
///
/// The filename to format.
/// Output filename, otherwise "".
public string FormatOutput(string filename) {
return (string)this.Wappsign.InvokeMember("FormatOutput", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { filename });
}
///
/// Returns the full error message given an error code.
///
/// Error code
/// Will return the error message. Passing 0 returns "WAPP0000: Successful sign!" and passing an invalid or unrecognized error will return "XXXX0000: An unspecificed error has occurred!"
public string GetErrorMessage(int errorCode) {
return (string)this.Wappsign.InvokeMember("GetErrorMessage", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { errorCode });
}
///
/// Adds a directory to the search path. All trailing slashes are removed.
///
/// Directory name to add.
/// Returns true if the path was successfully added. False if 10 directories are already in the search path.
public bool AddDirectory(string directory) {
return (bool)this.Wappsign.InvokeMember("AddDirectory", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { directory });
}
///
/// Removes a directory from the search path.
///
/// Directory path to remove.
/// True if directory was successfully removed. False if directory could not be found or removed.
public bool RemoveDirectory(string directory) {
return (bool)this.Wappsign.InvokeMember("RemoveDirectory", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { directory });
}
///
/// Retrieves the index-th directory from the search path.
///
/// Directory index.
/// Directory path name. Returns "" if the index is out of range.
public string GetDirectory(int index) {
return (string)this.Wappsign.InvokeMember("GetDirectory", BindingFlags.InvokeMethod, null, this.WappsignObj, new object[] { index });
}
}
}