Example #1
0
        public MainForm(Settings settings, string appSettingsDir, bool configFileExists)
        {
            InitializeComponent();
            _settings = settings;
            _appSettingsDir = appSettingsDir;
            _configFileExists = configFileExists;

            ReFillPicasaButtonList();
        }
        // Called by ADD button
        public CreatePicasaDBForm(string appSettingsDir, Settings settings)
        {
            InitializeComponent();

            _settings = settings;
            AppSettingsDir = appSettingsDir;
            //appSettingsBaseDir = Path.GetDirectoryName(AppSettingsDir);
            PicasaDB = new PicasaDB();
            PicDrivecomboBox.Text = "";
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Boolean isOK = false;
            Boolean createNewSettingsFile = false;

            try
            {
                Settings = SettingsHelper.DeSerializeSettings(AppSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                
                isOK = true;
            }
            catch (Exception)
            {
                // If the settings couldn't be loaded from default location, just create new empty 
                // settings object, but add default picasa database...
                if (IsDefaultLocation == true)
                {
                    createNewSettingsFile = true;
                    isOK = true;
                }
                // If no default location... ask for confirmation...
                else
                {
                    DialogResult result = MessageBox.Show(
                            "Settings file not found in this location:\n" + AppSettingsDir +
                            "\n\nSince this is not the default location for the settings file, " +
                            "you are probably trying to select a shared settings file that doesn't exist in this location.\n" +
                            "\n  -> Click YES to Create a New Settings File in this Location" +
                            "\n  -> Click NO to try a different location",
                            "No Settings File Found in This Location", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        // If the settings couldn't be loaded, create new empty settings object, but add default picasa database...
                        createNewSettingsFile = true;
                        isOK = true;
                    }
                }
            }

            if (createNewSettingsFile == true)
            {
                Settings = new Settings();
                Settings.picasaDBs.Add(SettingsHelper.GetDefaultPicasaDB());
            }

            if (isOK == true)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
 public CopyExistingDBForm( PicasaDB database, Settings settings)
 {
     InitializeComponent();
     _settings = settings;
     Db = database;
 }
Example #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Set version + build time in title bar
            this.Text = this.Text + " " + System.Diagnostics.FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileVersion
                + " on 2012-04-23 )" ;

            // If Picasa exe isn't found... ask path...
            if (!File.Exists(_settings.PicasaExePath))
            {
                FirstRunWizardStep1 firstRunWizardStep1 = new FirstRunWizardStep1(_settings.PicasaExePath);
                DialogResult result = firstRunWizardStep1.ShowDialog();

                if (result == DialogResult.OK)
                {
                    _settings.PicasaExePath = firstRunWizardStep1.PicasaExePath;
                }
                else
                {
                    this.Close();
                    return;
                }
            }

            // If new instance... ask for spot to put configuration file...
            if (_configFileExists == false)
            {
                FirstRunWizardStep2 firstRunWizardStep2 = new FirstRunWizardStep2(SettingsHelper.ConfigurationDir);
                DialogResult result = firstRunWizardStep2.ShowDialog();

                if (result == DialogResult.OK)
                {
                    _appSettingsDir = firstRunWizardStep2.AppSettingsDir;
                    //_VDriveBaseDir = Path.GetDirectoryName(_appSettingsDir);
                    _settings = firstRunWizardStep2.Settings;
                }
                else
                {
                    this.Close();
                    return;
                }

                Configuration config = new Configuration();
                if(firstRunWizardStep2.IsDefaultLocation)
                    config.picasaStarterSettingsXMLPath = "";
                else
                    config.picasaStarterSettingsXMLPath = _appSettingsDir;
                //config.configPicasaExePath = SettingsHelper.ProgramFilesx86();

                try
                {
                    SettingsHelper.SerializeConfig(config,
                            SettingsHelper.ConfigurationDir + "\\" + SettingsHelper.ConfigFileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error saving config file: " + ex.Message);
                }
            }

            // Initialise all controls on the screen with the proper data
            ReFillPicasaDBList(false);

            // If the saved defaultselectedDB is valid, select it in the list...
            int defaultSelectedDBIndex = listBoxPicasaDBs.FindStringExact(_settings.picasaDefaultSelectedDB);
            if (defaultSelectedDBIndex != ListBox.NoMatches)
            {
                listBoxPicasaDBs.SelectedIndex = defaultSelectedDBIndex;
                //Map the directory below the PicasaStarter Directory to the Virtual drive
                // if the drive is not mapped and virtual drive is enabled
                bool xxx = IOHelper.MapVirtualDrive(_settings.picasaDBs[defaultSelectedDBIndex], _appSettingsDir);
                if (xxx)
                {
                    MessageBox.Show("Error Mapping Virtual Drive" +
                     "\nCheck the Virtual Drive settings and Path.");
                }

            }
            saveListIndex = defaultSelectedDBIndex;
       }
Example #6
0
        private void buttonGeneralSettings_Click(object sender, EventArgs e)
        {
            GeneralSettingsDialog generalSettingsDialog = new GeneralSettingsDialog(_appSettingsDir, _settings.PicasaExePath);

            DialogResult result = generalSettingsDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (generalSettingsDialog.ReturnPicasaSettings != null)
                {
                    _settings = generalSettingsDialog.ReturnPicasaSettings;
                    // ReFillPicasaDBList(false);
                }
                _settings.PicasaExePath = generalSettingsDialog.ReturnPicasaExePath;
                _appSettingsDir = generalSettingsDialog.ReturnAppSettingsDir;
                //_VDriveBaseDir = Path.GetDirectoryName(_appSettingsDir);
                // Initialise all controls on the screen with the proper data
                ReFillPicasaDBList(false);
                // Save settings
                SaveSettings();
 
                // If the saved defaultselectedDB is valid, select it in the list...
                int defaultSelectedDBIndex = listBoxPicasaDBs.FindStringExact(_settings.picasaDefaultSelectedDB);
                if (defaultSelectedDBIndex != ListBox.NoMatches)
                    listBoxPicasaDBs.SelectedIndex = defaultSelectedDBIndex;
                saveListIndex = defaultSelectedDBIndex;
                bool xxx = IOHelper.MapVirtualDrive(_settings.picasaDBs[listBoxPicasaDBs.SelectedIndex], _appSettingsDir);
                if (xxx)
                {
                    MessageBox.Show("Error Mapping Virtual Drive" +
                     "\nCheck the Virtual Drive settings and Path.");
                }

            }
        }
 public RebuildRestoreForm(PicasaDB database, Settings settings)
 {
     InitializeComponent();
     _database = database;
     _settings = settings;
 }
Example #8
0
        static void Main()
        {
            #region Initialization
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string appSettingsDir = "";  //Directory containing PicasaStarter settings
            string configurationDir = "";
            Configuration config;
            Settings settings;
            bool ConfigFileExists = true;
            bool settingsfound = false;

            configurationDir = SettingsHelper.DetermineConfigDir();
            appSettingsDir = SettingsHelper.DetermineSettingsDir(configurationDir);
            try
            {
                settings = new Settings();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Picasa 3.9 Has not been Initialized for this user.\n" +
                    "Please run Picasa3 from the start menu to set up the registry.\n " +
                      "Error Msg:  " + ex.Message);
                return;

            }
            config = new Configuration();
            bool showGUI = true;


            try
            {
                config = SettingsHelper.DeSerializeConfig(
                    configurationDir + "\\" + SettingsHelper.ConfigFileName);
            }
            catch (Exception)
            {
                //No config file, set config & settings defaults and signal first time run
                ConfigFileExists = false;
                config.picasaStarterSettingsXMLPath = "";
                settings.picasaDBs.Add(SettingsHelper.GetDefaultPicasaDB());
            }
            // load settings...

            if (ConfigFileExists)
            {
                bool cancelSettingsFileSearch = false;
                string currentDir = appSettingsDir;
                currentDir = Path.GetDirectoryName(currentDir);


                while (!settingsfound && cancelSettingsFileSearch == false)
                {
                    if (!File.Exists(appSettingsDir + "\\" + SettingsHelper.SettingsFileName))
                    {
                        // Take care of case where the settings file is not available but it is referenced in the config file (The settings drive/dir is missing).
                        // Initializes the variables to pass to the MessageBox.Show method.
                        string message = "The Picasa Starter settings file was not found in:\n" + appSettingsDir + "\n\n If it is on a NAS or Portable Drive, " +
                            "\nPlease Connect the drive as the correct drive letter.\n" +
                            "When the Drive is connected, Push YES to Try Again.\n\n" +
                            "To define a new Settings File location, Push NO,\n" +
                            "Then Correct the Settings File location in the First Run dialog \n\n" +
                             "To Exit PicasaStarter Without Trying Again, Push CANCEL.";
                        string caption = "Missing Settings File";

                        // Displays the MessageBox.
                        DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNoCancel);

                        if (result == DialogResult.Yes)
                        {
                            settingsfound = false;
                        }
                        if (result == DialogResult.Cancel)
                        {
                            cancelSettingsFileSearch = true;
                            ConfigFileExists = false;
                            showGUI = false;
                        }
                        else if (result == DialogResult.No)
                        {
                            ConfigFileExists = false;
                            cancelSettingsFileSearch = true;
                            settings.picasaDBs.Add(SettingsHelper.GetDefaultPicasaDB());
                        }
                    }
                    else
                        settingsfound = true;
                }

                // Try to read the settings file...

                if (settingsfound == true)
                {
                    try
                    {
                        settings = SettingsHelper.DeSerializeSettings(
                            appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                        settingsfound = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error reading settings file: " + ex.Message);
                        settings.picasaDBs.Add(SettingsHelper.GetDefaultPicasaDB());
                        settingsfound = false;
                    }
                }
            }
            #endregion

            #region Process Command Line Arguments
            if (ConfigFileExists)
            {
               // Save settings
                //---------------------------------------------------------------------------
                try
                {
                    SettingsHelper.SerializeSettings(settings,
                            appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error saving settings: " + ex.Message);
                }

                // Process command line arguments...
                //---------------------------------------------------------------------------
                string autoRunDatabaseName = null;
                string backupDatabaseName = null;

                for (int i = 1; i < Environment.GetCommandLineArgs().Length; i++)
                {
                    string arg = Environment.GetCommandLineArgs()[i];

                    // Check if Picasastarter should autorun Picasa with a specified database name...
                    if (arg.Equals("/autorun", StringComparison.CurrentCultureIgnoreCase))
                    {
                        showGUI = false;

                        // The next argument should be the database name...
                        i++;
                        if (i < Environment.GetCommandLineArgs().Length)
                        {
                            autoRunDatabaseName = Environment.GetCommandLineArgs()[i];
                            autoRunDatabaseName = autoRunDatabaseName.Trim(new char[] { '"', ' ' });
                        }
                        else
                        {
                            MessageBox.Show("The /autorun directive should be followed by an existing Picasa database name, or \"Personal\" or \"AskUser\"", "No Database Name");
                        }
                    }
                    else if (arg.Equals("/backup", StringComparison.CurrentCultureIgnoreCase))
                    {
                        showGUI = false;

                        // The next argument should be the database name...
                        i++;
                        if (i < Environment.GetCommandLineArgs().Length)
                        {
                            backupDatabaseName = Environment.GetCommandLineArgs()[i];
                            backupDatabaseName = backupDatabaseName.Trim(new char[] { '"', ' ' });
                        }
                        else
                        {
                            MessageBox.Show("The /backup directive should be followed by an existing Picasa database name, or \"Personal\" or \"AskUser\"", "No Database Name");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid or no command line parameter: " + arg);
                    }
                }

                // If /autorun argument was passed...
                //---------------------------------------------------------------------------
                if (autoRunDatabaseName != null)
                {
                    PicasaDB foundDB = null;
                    if (IOHelper.IsProcessOpen("Picasa3"))
                    {
                        MessageBox.Show("Picasa 3 is presently running on this computer." +
                        "\n\nPlease Exit Picasa before trying to\nrun it from PicasaStarter", "Picasa Already Running");
                        return;
                    }

                    // First check if he wants to be asked which database to run
                    if (autoRunDatabaseName.Equals("AskUser", StringComparison.CurrentCultureIgnoreCase))
                    {
                        // Show Database selection menu 
                        SelectDBForm selectDBForm = new SelectDBForm(settings, false);
                        selectDBForm.ShowDialog();

                        if (selectDBForm.ReturnDBName != null)
                        {
                            autoRunDatabaseName = selectDBForm.ReturnDBName;
                        }
                        else
                            return;

                    }

                    // Next check if he wants to run with the standard personal database...
                    if (autoRunDatabaseName.Equals("personal", StringComparison.CurrentCultureIgnoreCase))
                    {
                        autoRunDatabaseName = settings.picasaDBs[0].Name;
                    }
                    foreach (PicasaDB db in settings.picasaDBs)
                    {
                        if (db.Name.Equals(autoRunDatabaseName, StringComparison.CurrentCultureIgnoreCase))
                            foundDB = db;
                    }

                    if (foundDB != null)
                    {
                        bool xxx = IOHelper.MapVirtualDrive(foundDB, appSettingsDir);
 
                        PicasaRunner runner = new PicasaRunner(settings.PicasaExePath);
                        String dbPath;
                        string destButtonDir;

                        // If the user wants to run his personal default database... 
                        if (foundDB.IsStandardDB == true)
                        {
                            dbPath = null;
                            // Set the directory to put the PicasaButtons in the PicasaDB...
                            destButtonDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
                                    "\\Google\\Picasa2\\buttons";
                        }

                        // If the user wants to run a custom database...
                        else
                        {
                            // Set the choosen BaseDir
                            if (!Directory.Exists(foundDB.BaseDir + "\\Google\\Picasa2") &&
                                Directory.Exists(foundDB.BaseDir + "\\Local Settings\\Application Data\\Google\\Picasa2"))
                            {

                                DialogResult result = MessageBox.Show("Do you want to temporarily use the Picasa version 3.8 database?\n" +
                                    "This Picasa 3.8 Database path is:\n " + foundDB.BaseDir + "\\Local Settings\\Application Data" +
                                    "\n\n Please edit the database settings, and convert the database to version 3.9 to stop receiving this warning message",
                                        "Database Not Converted for Picasa Version 3.9+", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
                                        (MessageBoxOptions)0x40000);
                                if (result == DialogResult.Yes)
                                {
                                    foundDB.BaseDir = foundDB.BaseDir + "\\Local Settings\\Application Data";
                                }
                            }
                            // Get out without creating a database if the database directory doesn't exist
                            if (!Directory.Exists(foundDB.BaseDir + "\\Google\\Picasa2"))
                            {
                                MessageBox.Show("The database doesn't exist at this location, please choose an existing database or create one.",
                                            "Database doesn't exist or not created", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1,
                                            (MessageBoxOptions)0x40000);
                                return;
                            }
                            dbPath = foundDB.BaseDir;
                            // Set the directory to put the PicasaButtons in the PicasaDB...
                            destButtonDir = foundDB.BaseDir + "\\Google\\Picasa2\\buttons";
                        }

                        // Copy Buttons and scripts and set the correct Path variable to be able to start scripts...
                        IOHelper.TryDeleteFiles(destButtonDir, "PSButton*");
                        foreach (PicasaButton button in settings.picasaButtons.ButtonList)
                        {
                            try
                            {
                                button.CreateButtonFile(destButtonDir);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }

                        settings.picasaButtons.Registerbuttons();

                        // Go!
                        try
                        {
                            runner.RunPicasa(dbPath, appSettingsDir);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                        bool xyz;
                        xyz = IOHelper.UnmapVDrive();

                    }
                    else
                    {
                        MessageBox.Show("The database passed with the /autorun parameter was not found: (" + autoRunDatabaseName + ")");
                        autoRunDatabaseName = null;
                    }
                }

                // If /backup argument was passed...
                //---------------------------------------------------------------------------
                if (backupDatabaseName != null)
                {
                    PicasaDB foundDB = null;
                    // First check if he wants to be asked which database to backup
                    if (backupDatabaseName.Equals("AskUser", StringComparison.CurrentCultureIgnoreCase))
                    {
                        // Show Database selection menu 
                        SelectDBForm selectDBForm = new SelectDBForm(settings, true);
                        selectDBForm.ShowDialog();

                        if (selectDBForm.ReturnDBName != null)
                        {
                            backupDatabaseName = selectDBForm.ReturnDBName;
                        }

                    }
                    // Next check if he wants to backup the standard personal database...
                    if (backupDatabaseName.Equals("personal", StringComparison.CurrentCultureIgnoreCase))
                    {
                        // If the user wants to backup his personal default database... (cmd line arg was "personal") 
                        Application.Run(new BackupForm_CL(settings.picasaDBs[0], appSettingsDir));
                        if (BackupComplete)
                        {
                            settings.picasaDBs[0].LastBackupDate = DateTime.Today;
                            try
                            {
                                SettingsHelper.SerializeSettings(settings,
                                        appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error saving settings: " + ex.Message);
                            }
                       }
                    }
                    else
                    {
                        // Exit if the Ask menu was cancelled
                        if (backupDatabaseName.Equals("AskUser", StringComparison.CurrentCultureIgnoreCase))
                        {
                            return;
                        }

                        foreach (PicasaDB db in settings.picasaDBs)
                        {
                            //MessageBox.Show("db: " + db.Name + "\nBackup name: " + backupDatabaseName);
                            if (db.Name.Equals(backupDatabaseName, StringComparison.CurrentCultureIgnoreCase))
                                foundDB = db;
                        }
                        //MessageBox.Show("Foundb: " + foundDB.Name + "\nBackup dir " + foundDB.BackupDir );

                        if (foundDB != null)
                        {
                            bool xxx = IOHelper.MapVirtualDrive(foundDB, appSettingsDir);

                            // Set backup date to now in settings and then save new date to settings file before backup
                            DateTime  SaveBUDate = foundDB.LastBackupDate;
                            foundDB.LastBackupDate = DateTime.Today;
                            try
                            {
                                SettingsHelper.SerializeSettings(settings,
                                        appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error saving settings: " + ex.Message);
                            }
                            Application.Run(new BackupForm_CL(foundDB, appSettingsDir));

                            //If backup was cancelled, try to restore settings file backup date to original
                            if (!BackupComplete)
                            {
                                // try to save old backup date if backup does not complete
                                foundDB.LastBackupDate = SaveBUDate;
                                try
                                {
                                    SettingsHelper.SerializeSettings(settings,
                                            appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Error saving settings: " + ex.Message);
                                }
                            }

                            bool xyz;
                            xyz = IOHelper.UnmapVDrive();


                        }
                        else
                        {
                            MessageBox.Show("The database passed with the /backup parameter was not found: (" + backupDatabaseName + ")");
                            backupDatabaseName = null;
                        }
                    }
                }
            }
            #endregion

            #region Start GUI

            if (showGUI == true)
            {
                Application.Run(new MainForm(settings, appSettingsDir, ConfigFileExists));
            }
            #endregion
        }
        // Called ny EDIT button
        public CreatePicasaDBForm(PicasaDB picasaDB, string appSettingsDir, Settings settings, bool standardDatabase = false)
        {
            InitializeComponent();

            AppSettingsDir = appSettingsDir;
            //appSettingsBaseDir = Path.GetDirectoryName(AppSettingsDir);
            //appSettingsBaseDir = Path.GetPathRoot(AppSettingsDir);
            PicasaDB = new PicasaDB(picasaDB);
            _settings = settings;

            //Backup Tab initialization
            textBoxBackupDir.Text = PicasaDB.BackupDir;
            if (string.IsNullOrEmpty(PicasaDB.BackupComputerName))
                textBoxBackupName.Text = "Not Defined";
            else
                textBoxBackupName.Text = PicasaDB.BackupComputerName;
            BackupFrequencyBox.SelectedIndex = PicasaDB.BackupFrequency;
            CheckBackupDBOnly.Checked = PicasaDB.BackupDBOnly;
            if (PicasaDB.LastBackupDate.Year <= 1900)
                textLastBackupDate.Text = "Never Backed Up";
            else
                textLastBackupDate.Text = PicasaDB.LastBackupDate.ToString("d");

            //Database Tab Initialization
            textBoxDBBaseDir.Text = PicasaDB.BaseDir;
            textBoxDBDescription.Text = PicasaDB.Description;
            textBoxDBName.Text = PicasaDB.Name;
            messageBoxDB.ForeColor = Color.Blue;
            messageBoxDB.Text = "";
            full38DBDirectory = PicasaDB.BaseDir + "\\Local Settings\\Application Data";

            //Virtual Drive Tab Initialization
            buttonVDRelPath.Checked = !PicasaDB.VirtualDrivePathAbsolute;
            buttonVDAbsPath.Checked = !buttonVDRelPath.Checked;
            PicDrivecomboBox.Text = PicasaDB.PictureVirtualDrive;
            EnablecheckBox.Checked = PicasaDB.EnableVirtualDrive;
            textBoxSourceRoot.Text = Path.GetPathRoot(AppSettingsDir);
            if (string.IsNullOrEmpty(PicasaDB.VirtualDriveBaseDir))
            {
                textBoxVDSource.Text = Path.GetDirectoryName(AppSettingsDir);
                buttonVDRelPath.Checked = true;
                buttonVDAbsPath.Checked = !buttonVDRelPath.Checked;
            }
            else
            {

                bool _VDPathRelative = buttonVDRelPath.Checked;
                string _VDriveBaseDir = PicasaDB.VirtualDriveBaseDir;
                string _VDriveBaseDirRoot = Path.GetPathRoot(_VDriveBaseDir);
                if (_VDPathRelative)
                {
                    int _VDRootLength = _VDriveBaseDirRoot.Length;
                    if (_VDriveBaseDirRoot.StartsWith("\\\\"))
                        _VDRootLength += 1;
                    string AppsBaseDirRoot = Path.GetPathRoot(AppSettingsDir);
                    string AppRootTrimmed = AppsBaseDirRoot.TrimEnd('\\');
                    if (_VDriveBaseDirRoot == _VDriveBaseDir)
                        _VDriveBaseDir = AppsBaseDirRoot;
                    else
                        _VDriveBaseDir = AppRootTrimmed + "\\" + _VDriveBaseDir.Substring(_VDRootLength);
                }

                textBoxVDSource.Text = _VDriveBaseDir;
            }

            //Disable options for Personal database
            if (standardDatabase == true)
            {
                textBoxDBName.Enabled = false;
                textBoxDBDescription.Enabled = false;
                buttonBrowseDBBaseDir.Enabled = false;
                BrowseVDSource.Enabled = false;
                buttonDoVDNow.Enabled = false;
                PicDrivecomboBox.Text = "C:";
                PicDrivecomboBox.Enabled = false;
                EnablecheckBox.Checked = false;
                EnablecheckBox.Enabled = false;
                buttonConvert38.Enabled = false;
            }
        }
Example #10
0
        public static void SerializeSettings(Settings settings, string settingsFilePath)
        {
            string NewSettingsText = "";
            string PresentSettingsText = "";

            Directory.CreateDirectory(Path.GetDirectoryName(settingsFilePath));

            try
            {
                // Serialize settings to file
                XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                using (TextWriter tw = new StreamWriter(settingsFilePath + ".tmp"))
                {
                    serializer.Serialize(tw, settings);
                }
                NewSettingsText = File.ReadAllText(settingsFilePath + ".tmp");
                if(File.Exists(settingsFilePath))
                    PresentSettingsText = File.ReadAllText(settingsFilePath);
                if (NewSettingsText != PresentSettingsText)
                {
                    // Serialize settings to file
                    //XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                    using (TextWriter tw = new StreamWriter(settingsFilePath))
                    {
                        serializer.Serialize(tw, settings);
                    }
                }
            }
            catch
            {
            }
            File.Delete(settingsFilePath + ".tmp");
        }
        private void SelXMLPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fd = new FolderBrowserDialog();
            fd.ShowNewFolderButton = true;
            fd.SelectedPath = _appSettingsDir;

            if (fd.ShowDialog() == DialogResult.OK)
            {
                textBoxSettingsXMLPath.Text = fd.SelectedPath;
                _appSettingsDir = textBoxSettingsXMLPath.Text.Trim(new char[] { '"', ' ' });
                _appSettingsDir = _appSettingsDir.TrimEnd(new char[] { '\\' });

                try
                {
                    _localSettings = SettingsHelper.DeSerializeSettings(
                    _appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                    _setDefaultIniPath = false;
                    _iniPathChanged = true;
                }
                catch (Exception)
                {
                    _iniPathChanged = false;

                    DialogResult result = MessageBox.Show(
                            "Settings file not found in this location:\n" + _appSettingsDir +
                            "\n\nSince this is not the default location for the settings file, " +
                            "you are probably trying to select a shared settings file that doesn't exist in this location." +
                            "\n\nClick YES to Create a New Settings File in this Location" +
                            "\n\nClick NO to try a different location",
                            "No Settings File Found in This Location", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        // If the settings couldn't be loaded, create new empty settings object, but add default picasa database...
                        _localSettings = new Settings();
                        _localSettings.picasaDBs.Add(SettingsHelper.GetDefaultPicasaDB());
                        _setDefaultIniPath = false;
                        _iniPathChanged = true;
                    }
                }
            }
        }
        private void SetXMLToDef_Click(object sender, EventArgs e)
        {
            textBoxSettingsXMLPath.Text = SettingsHelper.ConfigurationDir;
            _appSettingsDir = SettingsHelper.ConfigurationDir;
            try
            {
                _localSettings = SettingsHelper.DeSerializeSettings(
                    _appSettingsDir + "\\" + SettingsHelper.SettingsFileName);
                _setDefaultIniPath = true;
                _iniPathChanged = true;
            }
            catch (Exception)
            {
                _setDefaultIniPath = false;
                _iniPathChanged = false;

                DialogResult result = MessageBox.Show(
                        "Settings file not found in the default location:\n" + _appSettingsDir +
                        "\n\nClick YES to Create a New Settings File in the default Location" +
                        "\n\nClick NO then Cancel to select a different location.",
                        "No Settings File Found in the Default Location", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (result == DialogResult.Yes)
                {
                    // If the settings couldn't be loaded, create new empty settings object, but add default picasa database...
                    _localSettings = new Settings();
                    _localSettings.picasaDBs.Add(SettingsHelper.GetDefaultPicasaDB());
                    _setDefaultIniPath = true;
                    _iniPathChanged = true;
                }
            }
            //PicasaExePath = _localSettings.PicasaExePath;
            //_setDefaultIniPath = true;
            //_iniPathChanged = true;
        }
Example #13
0
 public SelectDBForm(Settings settings, bool IsBackup)
 {
     InitializeComponent();
     _settings = settings;
     _isBackup = IsBackup;
 }