예제 #1
0
        // Save backup of current settings and registry keys
        public string SaveBackup()
        {
            string errors = "";
            SteamController.ValidateSteamPath();
            Backup backup = new Backup(Guid.NewGuid(), DateTime.Now);

            if (!Directory.Exists("Backups"))
            {
                Directory.CreateDirectory("Backups");
            }

            string folder = "Backups\\" + backup.Id;
            Directory.CreateDirectory(folder);

            // Export registry keys to folder:
            exportKey("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout",
                folder + "\\Backup_CapsLock.reg");
            exportKey("HKEY_USERS\\.DEFAULT\\Control Panel\\Mouse", folder + "\\Backup_DefaultMouseKey.reg");
            exportKey("HKEY_CURRENT_USER\\Control Panel\\Mouse", folder + "\\Backup_MouseKey.reg");
            exportKey("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers",
                folder + "\\Backup_VisualThemes.reg");

            // Copy configs to folder:
            string[] cfgs = new string[] { SteamPaths.CfgFolder + "\\config.cfg",
                SteamPaths.CfgFolder + "\\video.txt", SteamPaths.Autoexec };

            foreach (string cfg in cfgs)
            {
                if (File.Exists(cfg))
                {
                    File.Copy(cfg, folder + "\\" + cfg.Split('\\').Last());
                }
                else
                {
                    errors += cfg + " was not found. \n";
                }
            }

            string[] dirs = Directory.GetDirectories(SteamPaths.Steam + @"\userdata\");
            foreach (string dir in dirs)
            {
                if (File.Exists(dir + @"\config\localconfig.vdf"))
                {
                    string[] pathSplit = dir.Split('\\');
                    string accountNumber = pathSplit[pathSplit.Count() - 1];
                    File.Copy(dir + @"\config\localconfig.vdf", folder + "\\" + accountNumber + "_localconfig.vdf");
                    backup.Localconfigs.Add(accountNumber + "_localconfig.vdf");
                }
            }
            File.WriteAllLines(folder + "\\localconfigs.txt", backup.Localconfigs);

            File.WriteAllLines(folder + "\\backup.txt", backup.ToStringArray());

            // Add backup list and return success message:
            backups.Add(backup);
            return errors + "Backup ("+backup.Id+") succesfully saved. \n";
        }
예제 #2
0
 // Create Backup objects from folder, and add to list.
 private void createBackups()
 {
     if (!Directory.Exists("Backups"))
     {
         Directory.CreateDirectory("Backups");
     }
     string[] backupDirs = Directory.GetDirectories("Backups\\");
     foreach (string backupDir in backupDirs)
     {
         // Read backup.txt settings file:
         string backupPath = backupDir + "\\backup.txt";
         if (File.Exists(backupPath))
         {
             string[] backupTxt = File.ReadAllLines(backupPath);
             Backup backup = new Backup(Guid.NewGuid(), DateTime.Parse("18-06-1990 13:37"));
             foreach (string line in backupTxt)
             {
                 if (line.Contains("Id = "))
                 {
                     Guid id;
                     Guid.TryParse(line.Split('=').Last().Replace(" ", ""), out id);
                     backup.Id = id;
                 }
                 if (line.Contains("Timestamp = "))
                 {
                     DateTime timestamp;
                     DateTime.TryParse(line.Split('=').Last(), out timestamp);
                     backup.Timestamp = timestamp;
                 }
             }
             // Read localconfigs.txt settings file:
             if (File.Exists(backupDir + "\\localconfigs.txt"))
             {
                 string[] localconfigs = File.ReadAllLines(backupDir + "\\localconfigs.txt");
                 foreach (string localconfig in localconfigs)
                 {
                     backup.Localconfigs.Add(localconfig);
                 }
             }
             backups.Add(backup);
         }
     }
 }