Exemplo n.º 1
0
 internal void refreshSaveFileChoice()
 {
     if (saveFileGroupBox.Enabled)   // Don't permit tabbing out and back during modification operations to risk changing the save file
     {
         string saveFile = TAB.GetMostRecentSave(saveOpenFileDialog.InitialDirectory);
         if (saveFile != null)
         {
             saveOpenFileDialog.FileName = saveFile; // No need to Path.GetFileName( saveFile ), doesn't help FileDialog only displaying the last ~8.3 chars
             setSaveFile(saveFile);
         }
     }
 }
Exemplo n.º 2
0
        private void saveFileChooseButton_Click(object sender, EventArgs e)
        {
            if (saveOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = saveOpenFileDialog.FileName;
                if (TAB.IsFileWithinDirectory(file, BackupsManager.DEFAULT_BACKUP_DIRECTORY))       // Doesn't use a dynamic value for the current backups directory, from the other tab's BackupManager...
                {
                    // Editing a backup will not trigger a checksum update once the modified file is repacked, confuses AutoBackup UI
                    statusWriter("Please do not modify files within the backups directory: " + file);
                    return;
                }

                setSaveFile(file);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string TABdirectory = args.Length >= 1 ? args[0] : TAB.GetExeDirectory();

            string savesDirectory = args.Length >= 2 ? args[1] : TAB.DEFAULT_SAVES_DIRECTORY;

            if (AttachConsole(ATTACH_PARENT_PROCESS))
            {
                Console.WriteLine("They Are Billions directory:\t" + TABdirectory);
                Console.WriteLine("Saves directory:\t\t" + savesDirectory);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainWindow(TABdirectory, savesDirectory));
        }
Exemplo n.º 4
0
        internal string generateChecksum(string saveFile)
        {
            if (state != ReflectorState.STARTED)
            {
                throw new InvalidOperationException("Reflector is not awaiting processing.");
            }

            state = ReflectorState.PROCESSING;

            writePipe(Char.ToString((char)PipeFlowControl.GenerateChecksum));
            writePipe(saveFile);
            string signature = readPipe();

            string checkFile = TAB.getCheckFile(saveFile);

            // Could first check if the existing contents are the same, and if so not overwrite. Unless something is expecting/needing LastModified to change?
            File.WriteAllText(checkFile, signature);

            state = ReflectorState.STARTED;
            return(signature);
        }
Exemplo n.º 5
0
        internal string repackDirAsSave()
        {
            if (state != SaveState.EXTRACTED)
            {
                throw new InvalidOperationException("Save File has not been extracted.");
            }
            // Don't create unencrypted saves where TAB or auto-backup watchers might see them
            string unencryptedSaveFile = Path.Combine(Path.GetTempPath(), Path.GetFileName(currentSaveFile));

            repackExtracted(unencryptedSaveFile, currentDecryptDir);

            string password = signAndGeneratePassword(unencryptedSaveFile);

            // Purge the temporary unencrypted versions of this new save file
            File.Delete(unencryptedSaveFile);
            File.Delete(TAB.getCheckFile(unencryptedSaveFile));

            repackExtracted(currentSaveFile, currentDecryptDir, password);

            signAndGeneratePassword(currentSaveFile, false);

            return(currentSaveFile);
        }
Exemplo n.º 6
0
        internal string generatePassword(string saveFile)
        {
            if (state != ReflectorState.STARTED)
            {
                throw new InvalidOperationException("Reflector is not awaiting processing.");
            }

            string checkFile = TAB.getCheckFile(saveFile);

            if (!File.Exists(checkFile))
            {
                // Generate checksum file first?
                throw new InvalidOperationException("Check file not found: " + checkFile);
            }

            state = ReflectorState.PROCESSING;

            writePipe(Char.ToString((char)PipeFlowControl.GeneratePassword));
            writePipe(saveFile);
            string password = readPipe();

            state = ReflectorState.STARTED;
            return(password);
        }
Exemplo n.º 7
0
        private SaveState state;    // Should lock() access?


        private static string backupSave(string saveFile, string backupDir, bool tryCheckFile)       // Refactor this into new BackupsManager features?
        {
            if (!File.Exists(saveFile))
            {
                Console.Error.WriteLine("Save file does not exist: " + saveFile);
                return(null);
            }

            // Figure out a filename that isn't taken
            string saveFileName = Path.GetFileName(saveFile);

            FileInfo[] backupsInfo = new DirectoryInfo(backupDir).GetFiles(saveFileName + ".*");
            int        suffix      = backupsInfo.Length + 1;
            string     backupFile  = Path.Combine(backupDir, saveFileName) + '.' + suffix;

            if (File.Exists(backupFile))
            {
                Console.Error.WriteLine("Backup already exists: " + backupFile);
                return(null);
            }

            // Move the old zip
            try
            {
                File.Move(saveFile, backupFile);
            }
            catch
            {
                Console.Error.WriteLine("Unable to backup: " + saveFile + " to: " + backupFile);
                return(null);
            }

            if (tryCheckFile)
            {
                // Try to backup the check file too, but don't fail the overall method if this can't be done
                string checkFile = TAB.getCheckFile(saveFile);
                if (!File.Exists(checkFile))
                {
                    Console.Error.WriteLine("Check file does not exist: " + checkFile);
                }
                else
                {
                    string backupCheckFile = Path.Combine(backupDir, Path.GetFileName(checkFile)) + '.' + suffix;
                    if (File.Exists(backupCheckFile))
                    {
                        Console.Error.WriteLine("Check backup already exists: " + backupCheckFile);
                    }
                    else
                    {
                        try
                        {
                            File.Move(checkFile, backupCheckFile);
                        }
                        catch
                        {
                            Console.Error.WriteLine("Unable to backup: " + checkFile + " to: " + backupCheckFile);
                        }
                    }
                }
            }

            return(backupFile);
        }