private void Set_Click(object sender, RoutedEventArgs e)
 {
     RegistryManipulator.WriteRegistry(baseRegistryKey, dCSBackupToolSubKey, "BackupPath", this.usersBackupPath);
     RegistryManipulator.WriteRegistry(baseRegistryKey, dCSBackupToolSubKey, "SavedGames", this.usersSavedGames);
     RegistryManipulator.WriteRegistry(baseRegistryKey, dCSBackupToolSubKey, "DCS World", this.usersDCSworldPath);
     RegistryManipulator.WriteRegistry(baseRegistryKey, dCSBackupToolSubKey, "Helios", this.usersHeliosPath);
     RegistryManipulator.WriteRegistry(baseRegistryKey, dCSBackupToolSubKey, "Jsgme", this.usersJsgmePath);
     this.Close();
 }
        private void GetSettingsValues()
        {
            //get backup location
            this.usersBackupPath = RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "BackupPath");
            if (this.usersBackupPath == null)
            {
                BackupLocationText.Text = "Select a backup location";
            }
            else
            {
                BackupLocationText.Text = this.usersBackupPath;
            }

            //get saved games
            this.usersSavedGames = RegistryManipulator.ReadRegistry(baseRegistryKey, dCSBackupToolSubKey, "SavedGames");
            if (this.usersSavedGames == null)
            {
                this.usersHomePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                string dcsSavedGames = this.usersHomePath + "\\Saved Games\\DCS";
                this.usersSavedGames = dcsSavedGames;
                savedGamesText.Text  = dcsSavedGames;
            }
            else
            {
                savedGamesText.Text = this.usersSavedGames;
            }

            //get dcsWorld location my setting first if in registry
            this.usersDCSworldPath = RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "DCS World");
            if (this.usersDCSworldPath == null)
            {
                //get eagle dynamics setting
                this.usersDCSworldPath = RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.eDPathSubKey, "Path");
            }
            if (this.usersDCSworldPath != null)
            {
                DCSWorldText.Text = this.usersDCSworldPath;
            }
            else
            {
                DCSWorldText.Text = "Can not find DCS. Enter path to DCS";
            }

            //get helios path
            this.usersHeliosPath = RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "Helios");
            if (this.usersHeliosPath == null)
            {
                //usual helios path
                HeliosText.Text    = "If installed choose location";
                HeliosText.ToolTip = "Usual path is " + this.usersHomePath + "\\Documents\\Helios";
            }
            else
            {
                HeliosText.Text = this.usersHeliosPath;
            }
            //get jsgme path
            this.usersJsgmePath = RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "Jsgme");
            if (this.usersJsgmePath == null)
            {
                JsgmeText.ToolTip = "Select path for JSGME folder if your using one";
            }
            else
            {
                JsgmeText.Text = this.usersJsgmePath;
            }
        }
Exemplo n.º 3
0
        private void ThreadBackupFolders()
        {
            //start time
            string        backupLocations = null;
            int           result          = Environment.TickCount & Int32.MaxValue;
            StringBuilder textOut         = new StringBuilder();

            textOut.Append("Starting Backup\n");
            SetProgressBar(true);

            try
            {
                string backupPath = RegistryManipulator.ReadRegistry(this.baseRegistryKey,
                                                                     this.dCSBackupToolSubKey, "BackupPath");

                if (!Directory.Exists(backupPath))
                {
                    SetProgressBar(false);
                    throw new ApplicationException("Backup location " + backupPath + " does not exist");
                }

                List <string> foldersToBackup = new List <string>();
                foldersToBackup.Add(RegistryManipulator.ReadRegistry(baseRegistryKey, dCSBackupToolSubKey, "SavedGames"));
                foldersToBackup.Add(RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "DCS World"));
                foldersToBackup.Add(RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "Helios"));
                foldersToBackup.Add(RegistryManipulator.ReadRegistry(this.baseRegistryKey, this.dCSBackupToolSubKey, "Jsgme"));

                foreach (string fol in foldersToBackup)
                {
                    if (fol != null)
                    {
                        //check each folder exists before copying
                        if (Directory.Exists(fol))
                        {
                            //get the name of the folder from the original path
                            string dirName = new DirectoryInfo(fol).Name;
                            //append the directory name to the backuplocation
                            backupLocations = backupPath + "\\" + dirName;
                            //check for existing backup folder if so delete
                            if (Directory.Exists(backupLocations))
                            {
                                //If you have the specified directory open in File Explorer
                                //the Delete method may not be able to delete it
                                Directory.Delete(backupLocations, true);
                                textOut.Append(backupLocations + " deleted\n");
                                WriteToTextBlock(textOut.ToString());
                            }
                            CopyDirectory(fol, backupLocations, true);
                            textOut.Append(fol + " backed up\n");
                            WriteToTextBlock(textOut.ToString());
                        }
                        else
                        {
                            SetProgressBar(false);
                            throw new ApplicationException(fol + " does not exist");
                        }
                    }
                }

                //finish time
                SetProgressBar(false);
                int    result2   = Environment.TickCount & Int32.MaxValue;
                string timeTaken = ((result2 - result) / 1000).ToString();
                textOut.Append("Copy took " + timeTaken + " seconds");
                WriteToTextBlock(textOut.ToString());
            }
            catch (Exception oError)
            {
                WriteToTextBlock(oError.Message);
            }
        }