예제 #1
0
 //Constructor
 public ProfileManager(ref Clicktastic.ProfileData profileData)
 {
     data = profileData;
     InitializeComponent();
     foreach (string file in Directory.GetFiles(currentDirectory, "*.clk"))
     {
         lbProfiles.Items.Add(Path.GetFileNameWithoutExtension(file));
     }
 }
예제 #2
0
        //===========================================================================
        //
        // Public Functions
        //
        //===========================================================================
        //
        // Load(string name, ref Clicktastic.ProfileData profile)
        // Attempts to load a profile from a file into a ProfileData structure
        //
        public Boolean Load(string name, ref Clicktastic.ProfileData profile)
        {
            Boolean success = false;
            BinaryReader b = null;
            try
            {
                //Open the file
                b = new BinaryReader(File.Open(currentDirectory + "\\" + name + ".clk", FileMode.Open));

                //Check the header
                if (b.ReadString() != "Clicktastic Profile")
                {
                    success = false; //header was invalid
                    throw new Exception("File is not a Clicktastic profile!");
                }

                //Load the KEYCOMBO structures
                if (!LoadKEYCOMBO(b, ref profile.ActivationKey))
                {
                    success = false;
                    throw new Exception("ActivationKey could not be loaded!");
                }
                if (!LoadKEYCOMBO(b, ref profile.DeactivationKey))
                {
                    success = false;
                    throw new Exception("DeactivationKey could not be loaded!");
                }
                if (!LoadKEYCOMBO(b, ref profile.AutoclickKey))
                {
                    success = false;
                    throw new Exception("AutoclickKey could not be loaded!");
                }

                //Load all other profile data
                profile.random = b.ReadBoolean();
                profile.hold = b.ReadBoolean();
                profile.pressEnter = b.ReadBoolean();
                profile.useDeactivationKey = b.ReadBoolean();
                profile.suppressHotkeys = b.ReadBoolean();
                profile.mute = b.ReadBoolean();
                profile.loadSound = b.ReadBoolean();
                profile.alwaysPlay = b.ReadBoolean();
                profile.turbo = b.ReadInt32();
                profile.MinDelay = b.ReadInt32();
                profile.MaxDelay = b.ReadInt32();

                success = true;
            }
            catch
            { //something went wrong
                success = false;
            }
            finally
            {
                if (b != null)
                {
                    b.Close(); //all done with the file
                    b.Dispose();
                }
            }
            return success;
        }
예제 #3
0
 //
 // LoadKEYCOMBO(BinaryReader b, ref Clicktastic.KEYCOMBO key)
 // Attempts to load a KEYCOMBO structure from a file
 //
 private Boolean LoadKEYCOMBO(BinaryReader b, ref Clicktastic.KEYCOMBO key)
 {
     try
     {
         key.valid = b.ReadBoolean();
         if (!key.valid) //key must be valid
             throw new Exception("KEYCOMBO is not valid!");
         key.isKeyboard = b.ReadBoolean();
         key.modifierKeys = GetKey(b.ReadBytes(KeySize));
         key.key = GetKey(b.ReadBytes(KeySize));
         key.keyString = b.ReadString();
         key.cmd = b.ReadString();
         key.mouseButton = b.ReadUInt32();
         key.wheel = b.ReadInt32();
     }
     catch
     {
         return false;
     }
     return true;
 }
예제 #4
0
 //
 // SaveKEYCOMBO(BinaryWriter b, Clicktastic.KEYCOMBO key)
 // Attempts to save a KEYCOMBO structure to a file
 //
 private Boolean SaveKEYCOMBO(BinaryWriter b, Clicktastic.KEYCOMBO key)
 {
     try
     {
         if (!key.valid) //key must be valid
             throw new Exception("KEYCOMBO is not valid!");
         b.Write(key.valid);
         b.Write(key.isKeyboard);
         b.Write(GetBytes(key.modifierKeys));
         b.Write(GetBytes(key.key));
         b.Write(key.keyString);
         b.Write(key.cmd);
         b.Write(key.mouseButton);
         b.Write(key.wheel);
     }
     catch
     {
         return false;
     }
     return true;
 }
예제 #5
0
        //
        // Save(string name, ref Clicktastic.ProfileData profile)
        // Attempts to save a profile to a file from a ProfileData structure
        //
        public Boolean Save(string name, ref Clicktastic.ProfileData profile)
        {
            Boolean success = false;
            BinaryWriter b = null;
            try
            {
                if (!Directory.Exists(currentDirectory)) //make sure the profile directory exists
                    Directory.CreateDirectory(currentDirectory); //if not, create it

                //Open the file
                b = new BinaryWriter(File.Open(currentDirectory + "\\" + name + ".clk", FileMode.OpenOrCreate));

                //Write the header
                b.Write("Clicktastic Profile");

                //Save the KEYCOMBO structures
                if (!SaveKEYCOMBO(b, profile.ActivationKey))
                    throw new Exception("ActivationKey could not be saved!");
                if (!SaveKEYCOMBO(b, profile.DeactivationKey))
                    throw new Exception("DeactivationKey could not be saved!");
                if (!SaveKEYCOMBO(b, profile.AutoclickKey))
                    throw new Exception("AutoclickKey could not be saved!");

                //Save all other profile data
                b.Write(profile.random);
                b.Write(profile.hold);
                b.Write(profile.pressEnter);
                b.Write(profile.useDeactivationKey);
                b.Write(profile.suppressHotkeys);
                b.Write(profile.mute);
                b.Write(profile.loadSound);
                b.Write(profile.alwaysPlay);
                b.Write(profile.turbo);
                b.Write(profile.MinDelay);
                b.Write(profile.MaxDelay);

                success = true;
            }
            catch
            { //something went wrong
                success = false;
            }
            finally
            {
                if (b != null)
                {
                    b.Close(); //all done with the file
                    b.Dispose();
                }
            }
            return success;
        }