public MainForm() { InitializeComponent(); // Initialize all local fields _preferenceLocations = new PreferenceLocations(); _globalPreferences = new GlobalPreferences(); _localPreferences = new LocalPreferences(); }
public InitialSetupForm(PreferenceLocations preferenceLocations) { InitializeComponent(); _preferenceLocations = preferenceLocations; // Initialize text boxes with locations read from preference file, in case some existed. // (If all exist, it shouldn't launch this Initial Setup at all) txtDropboxFolderLocation.Text = _preferenceLocations.DropboxLocation; txtGlobalPreferenceFileLocation.Text = _preferenceLocations.GlobalPreferenceLocation; txtLocalPreferenceFileLocation.Text = _preferenceLocations.LocalPreferenceLocation; }
/** * Load the PreferenceLocations.cs file to learn where GlobalPreferences.cs * and LocalPreferences.cs are, and then load them as well. * * Returns 'true' if the program should show Initial Setup dialog. **/ private bool LoadPreferences(bool isFirstRun) { if (isFirstRun) { // Read PreferenceLocations.js file and deserialize into PreferenceLocations object for easier usage. using (FileStream fileStream = new FileStream(_kPreferenceLocationFileName, FileMode.OpenOrCreate, FileAccess.Read)) { if (fileStream.Length == 0) return true; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof (PreferenceLocations)); _preferenceLocations = serializer.ReadObject(fileStream) as PreferenceLocations; } } // Check if each of the locations are specified. If any are missing, set isMissing to true. bool isMissing = (_preferenceLocations == null); if (!isMissing) { if (_preferenceLocations.DropboxLocation == null || _preferenceLocations.DropboxLocation.Length <= 0) isMissing = true; if (_preferenceLocations.GlobalPreferenceLocation == null || _preferenceLocations.GlobalPreferenceLocation.Length <= 0) isMissing = true; else { // If Global Preferences are not missing, then load them. LoadGlobalPreferences(); } if (_preferenceLocations.LocalPreferenceLocation == null || _preferenceLocations.LocalPreferenceLocation.Length <= 0) isMissing = true; else { // If Local Preferences are not missing, then load them. LoadLocalPreferences(); } } return isMissing; }