public NodeProfile LoadProfile(String filePath) { NodeProfile profile = null; using (Stream stream = File.OpenRead(filePath)) { BinaryFormatter formatter = new BinaryFormatter(); profile = (NodeProfile)formatter.Deserialize(stream); } if (IndexOfLoadedProfileWithFilePath(profile.FilePath) != -1) { OnProfileControllerAction( new ProfileControllerActionEventArgs(GameBotGUI.Profile.ProfileControllerAction.AlreadyLoaded, profile)); } else { RemoveFromProfilesWhereFilePathExists(profile); Profiles.Add(profile); _activeProfile = profile; profile.Loaded = true; OnProfileControllerAction( new ProfileControllerActionEventArgs(GameBotGUI.Profile.ProfileControllerAction.Load, profile)); } return(profile); }
public void RemoveFromProfilesWhereFilePathExists(NodeProfile profile) { int ndx = IndexOfProfileWithFilePath(profile.FilePath); if (ndx != -1) { Profiles.RemoveAt(ndx); } }
public void SaveProfile(NodeProfile profile) { using (Stream stream = File.Open(profile.FilePath, FileMode.Create)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, profile); } if (IndexOfProfileWithFilePath(profile.FilePath) == -1) { Profiles.Insert(0, profile); } OnProfileControllerAction( new ProfileControllerActionEventArgs(GameBotGUI.Profile.ProfileControllerAction.Save, profile)); }
private void GBGMain_Load(Object sender, EventArgs e) { ttUpdater.Interval = 500; ttUpdater.Tick += new EventHandler((o, ev) => { long mil = totalRunTime.ElapsedMilliseconds, seconds = mil / 1000, minutes = seconds / 60 % 60, hours = minutes / 60, days = hours / 24; lblCurrentRunTime.Text = "Approx. " + days + "d " + (hours % 24) + "h " + (minutes % 60) + "m " + (seconds % 60) + "s"; }); bgw.WorkerSupportsCancellation = true; bgw.WorkerReportsProgress = true; bgw.DoWork += new DoWorkEventHandler(RunBot_Work); bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged); bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted); Hotkey hkRunBot = new Hotkey(Keys.F12, false, true, true, false); hkRunBot.Pressed += delegate { if (btnStopBot.Enabled) StopBot(); else if (btnRunBot.Enabled) RunBot(); }; hkRunBot.Register(this); Text += ASMVersion; WriteLogLine("Version: ", ASMVersion); WriteLogLine("Disclaimer: if you get caught, it's not my nor anyone else's problem. " + "This understanding should be tacit. Deal with it (or don't use the " + "program). By using this program you are agreeing to hold no one " + "other than your cheating self responsible if anything goes wrong. " + "Don't even attempt to contact me."); WriteLogLine("Oh, and you should probably consider disabling the UAC when running ", "this bot, especially if you're encountering problems."); WriteLogLine("Finishing initialization..."); ResetRunStatistics(); long frequency = Stopwatch.Frequency; long nanosecPerTick = (1000L * 1000L * 1000L) / frequency; WriteLogLine("**Timer frequency in ticks per second = ", frequency); WriteLogLine("*-*Duration stopwatch estimated to be accurate to within ", nanosecPerTick, " nanoseconds on this system"); // Load/Save dialogs saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Choose Profile Location..."; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Select Profile..."; saveFileDialog.InitialDirectory = openFileDialog.InitialDirectory = profileController.DefaultSaveDirectory; saveFileDialog.DefaultExt = openFileDialog.DefaultExt = Properties.Settings.Default.ProfileFileExtension; saveFileDialog.Filter = openFileDialog.Filter = "profiles (*." + Properties.Settings.Default.ProfileFileExtension + ")|*." + Properties.Settings.Default.ProfileFileExtension + "|All files (*.*)|*.*"; // Set up MouseTracker Timer mouseTrackerTimer = new Timer(); mouseTrackerTimer.Interval = 200; mouseTrackerTimer.Tick += new EventHandler(mouseTrackerTimer_Tick); // Set up events profileController.Profiles.ListChanged += new ListChangedEventHandler((o, ev) => { if(profileController.Profiles.Count > 0) cbProfileSelector.Enabled = true; else cbProfileSelector.Enabled = false; }); lbNodesListChangedEventHandler = new ListChangedEventHandler(nodeList_ListChanged); // ListControls cbProfileSelector.DataSource = profileController.Profiles; lbNodes.DisplayMember = "Display"; cbProfileSelector.DisplayMember = "Display"; // Load/Create the default profile profileController.ProfileControllerAction += new ProfileController.ProfileControllerActionHandler(profileController_ProfileControllerAction); String errpath = "(unknown location)"; mouseTrackerTimer.Enabled = true; try { EnableInitialControls(); if(File.Exists(profileController.PathOfDefaultProfile)) profileController.LoadProfile(errpath = profileController.PathOfDefaultProfile); else { NodeProfile profile = new NodeProfile("default", profileController.DefaultSaveDirectory, new BindingList<GenericNode>()); errpath = profile.FilePath; profileController.SaveProfile(profile); profileController.LoadProfile(profile.FilePath); } SetCurrentAction("Idle (fully initialized)"); elbNodes = new ExtendedListControl<GenericNode>(lbNodes); profileController.Profiles.ResetBindings(); } catch(System.Runtime.Serialization.SerializationException ouch) { WriteLogLine( "ERROR: Failed to mutate your default profile.", "If you continue to see this error, please ", "delete the following file: \"", errpath, "\"."); WriteLogLine("WARNING: Due to Profile functionality being unavailable for the duration ", "of this session, program functionality has become limited."); menuStripMain.Enabled = false; SetCurrentAction("Idle (bad startup; check logs)"); } }
public ProfileControllerActionEventArgs(ProfileControllerAction action, NodeProfile profile) { Action = action; Profile = profile; }
public NodeProfile LoadProfile(String filePath) { NodeProfile profile = null; using(Stream stream = File.OpenRead(filePath)) { BinaryFormatter formatter = new BinaryFormatter(); profile = (NodeProfile) formatter.Deserialize(stream); } if(IndexOfLoadedProfileWithFilePath(profile.FilePath) != -1) { OnProfileControllerAction( new ProfileControllerActionEventArgs(GameBotGUI.Profile.ProfileControllerAction.AlreadyLoaded, profile)); } else { RemoveFromProfilesWhereFilePathExists(profile); Profiles.Add(profile); _activeProfile = profile; profile.Loaded = true; OnProfileControllerAction( new ProfileControllerActionEventArgs(GameBotGUI.Profile.ProfileControllerAction.Load, profile)); } return profile; }
public void SaveProfile(NodeProfile profile) { using(Stream stream = File.Open(profile.FilePath, FileMode.Create)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, profile); } if(IndexOfProfileWithFilePath(profile.FilePath) == -1) Profiles.Insert(0, profile); OnProfileControllerAction( new ProfileControllerActionEventArgs(GameBotGUI.Profile.ProfileControllerAction.Save, profile)); }
public void RemoveFromProfilesWhereFilePathExists(NodeProfile profile) { int ndx = IndexOfProfileWithFilePath(profile.FilePath); if(ndx != -1) Profiles.RemoveAt(ndx); }