예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }