public static string[] Load(FrmScripter frmScp, MRU mru, string path) { if (!File.Exists(path)) { UtilSys.MessageBox("File '" + path + "' does not exist."); mru.Remove(path); mru.Save(); return(null); } frmScp.Output("Loading file: " + path); string[] buffer = UtilIO.ReadFile2Array(path); mru.Add(path); mru.Save(); return(buffer); }
} // static private bool NotifyUnsavedChanges() // // static public bool LoadProfile() // // A convenient centralised method returning boolean success or failure, LoadProfile directs Profile // to read a Profile from disk while ensuring that any currently open form reflects the opened Profile // status in its UI. This method considers whether a currently open Profile has unsaved edits, offering // the opportunity to persist the Profile. // // LoadProfile returns boolean success or failure. // static public bool LoadProfile(string filename) { // Offer to persist any unsaved Profile edits... if (Profile.IsEdited() && NotifyUnsavedChanges() == false) { return(false); } // Present the user with a File Open Dialog through which they may choose a Profile to load. if (filename == null) { using (OpenFileDialog profile_dialog = new OpenFileDialog()) { // Give the Dialog a title and then establish a filter to hide anything that isn't an XML // file by default. profile_dialog.Title = "Select a Profile to open"; profile_dialog.Filter = "Profiles (*.XML)|*.XML|All Files (*.*)|*.*"; // Try get the path to a directory within GAVPI's own directory called "Profiles", and make that // the default directory in the OpenFileDialog. string GAVPIPath = new Uri(System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).LocalPath; if (Directory.Exists(GAVPIPath + "\\Profiles")) { GAVPIPath += "\\Profiles"; } profile_dialog.InitialDirectory = GAVPIPath; if (profile_dialog.ShowDialog() == DialogResult.Cancel) { return(false); } // Save the loaded Profile's filename for convenience sake. filename = profile_dialog.FileName; } // if()... using()... } // Attempt to load the given Profile... if (!Profile.load_profile(filename)) { MessageBox.Show("There appears to be a problem with the Profile you have chosen.\n\n" + "The Profile may have been moved or deleted, or it may not be an\n" + "actual Profile. It may even have become corrupted. Please check\n" + "the Profile by attempting to open it in the Profile Editor.", "I cannot open the Profile", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return(false); } // if() // Clear the log before requesting frmGAVPI refresh its UI otherwise the ListBox may remain // populated. Log.Clear(); if (Application.OpenForms.OfType <frmGAVPI>().Count() > 0) { MainForm.RefreshUI(GetStatusString()); } if (Application.OpenForms.OfType <frmProfile>().Count() > 0) { ProfileEditor.RefreshUI(GetStatusString()); } // Let's enable or disable specific system tray menu items to reflect the application's state, // and the viable workflow. Finish by updating the system tray icon's tooltip to reflect the // loaded Profile. sysTrayMenu.MenuItems[MODIFY_PROFILE_MENU_ITEM].Enabled = true; sysTrayMenu.MenuItems[LISTEN_MENU_ITEM].Enabled = true; sysTrayMenu.MenuItems[STOP_LISTENING_MENU_ITEM].Enabled = false; sysTrayIcon.Text = APPLICATION_TITLE + ": " + Path.GetFileNameWithoutExtension(Profile.GetProfileFilename()); // And now we can add the loaded Profile to the MRU list. ProfileMRU.Add(Path.GetFileNameWithoutExtension(Profile.GetProfileFilename()), Profile.GetProfileFilename()); return(true); } // static public bool LoadProfile()