示例#1
0
        private void importBackup(string orgPath = null)
        {
            if (orgPath == null)
            {
                this.openFileDialogImport.Filter = "Database files|*" + Constants.BACKUP_EXTENSION;
                DialogResult result = this.openFileDialogImport.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                orgPath = this.openFileDialogImport.FileName;
            }
            // Get a copy of it, so we can change stuff
            string path = Path.GetTempFileName();

            File.Copy(orgPath, path, true);
            // Get its name out
            Database database = new Database(path);
            Settings settings = new Settings(database);

            // Invoking the properties form ensures that everything's valid: unique name, etc
            PropertiesForm propertiesForm = new PropertiesForm(settings, this.backups, true);

            propertiesForm.ShowDialog();
            propertiesForm.Close();

            string name = settings.Name;

            database.Close();

            if (!propertiesForm.Saved)
            {
                try {
                    File.Delete(path);
                }
                catch (IOException e) { this.showError(e.Message); }
                return;
            }

            // Move it to the right dir
            try {
                if (!Directory.Exists(this.backupsPath))
                {
                    Directory.CreateDirectory(this.backupsPath);
                }
                File.Move(path, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Constants.APPDATA_FOLDER, Constants.BACKUPS_FOLDER, name + Constants.BACKUP_EXTENSION));
            }
            catch (IOException e) { this.showError(e.Message); }
            this.populateBackupsList();
        }
示例#2
0
        private void buttonProperties_Click(object sender, EventArgs e)
        {
            string fileName = this.loadSelectedBackup();

            if (fileName == null)
            {
                return;
            }
            Database database = new Database(fileName);

            try {
                database.Lock();
            }
            catch (Database.DatabaseInUseException) {
                this.showError("The database is currently in use (lockfile exists). Are you running this backup elsewhere?");
                database.Close();
                return;
            }
            Settings settings = new Settings(database);

            PropertiesForm propertiesForm = new PropertiesForm(settings, this.backups);

            propertiesForm.ShowDialog();
            propertiesForm.Close();

            // need to close DB before move
            string afterName = Path.Combine(this.backupsPath, settings.Name) + Constants.BACKUP_EXTENSION;

            database.Close();

            if (afterName != fileName)
            {
                try {
                    File.Move(fileName, afterName);
                }
                catch (IOException ex) { this.showError(ex.Message); }
                this.populateBackupsList();
            }
            this.updateInfoDisplay();
        }
示例#3
0
        private void createBackup()
        {
            string   tempFile   = Path.GetTempFileName();
            Database database   = Database.CreateDatabase(tempFile);
            Settings settings   = new Settings(database);
            string   backupName = "Unnamed Backup";

            for (int i = 2; this.backups.Contains(backupName); i++)
            {
                backupName = String.Format("Unnamed Backup {0}", i);
            }
            settings.PopulateInitial(backupName);

            PropertiesForm propertiesForm = new PropertiesForm(settings, this.backups);

            propertiesForm.ShowDialog();

            if (propertiesForm.Saved == false)
            {
                database.Close();
                return;
            }

            propertiesForm.Close();

            string destFile = Path.Combine(this.backupsPath, settings.Name + Constants.BACKUP_EXTENSION);

            database.Close();

            try {
                if (!Directory.Exists(this.backupsPath))
                {
                    Directory.CreateDirectory(this.backupsPath);
                }
                File.Move(tempFile, destFile);
            }
            catch (IOException e) { this.showError(e.Message); }
            this.populateBackupsList();
        }