private void Conf_RestoreDlg_Load(object sender, EventArgs e)
        {
            dbBackup = new DatabaseBackup();
            dbBackup.BackupProgress += dbBackup_OnBackupProgress;
            dbBackup.BackupError += dbBackup_OnBackupDataError;
            dbBackup.Completed += dbBackup_Completed;
            if (backup)
            {
                dbBackup.BackupThumbs = backupThumbs;
            }
            else
            {
                dbBackup.RestoreThumbs = restoreThumbs;
                dbBackup.EmulatorMergeType = emulatorMergeType;
                dbBackup.GameMergeType = gameMergeType;
                dbBackup.CleanRestore = CleanRestore;
            }

            worker = new Thread(new ThreadStart(delegate()
                {
                    if (backup)
                        dbBackup.Backup(path);
                    else
                        dbBackup.Restore(path);
                }));
            worker.Start();
        }
Example #2
0
        /// <summary>
        /// Process returns a copy of the media database, and can be used to return SQL deltas to update
        /// the local copy of the media database
        /// </summary>
        public void Process(UriWrapper uri, IHttpProcessor processor, User user)
        {
            // If ID set, return all queries >= this id
            if (uri.Id != null)
            {
                processor.WriteJson(new DatabaseResponse(null, Injection.Kernel.Get <IDatabase>().QueryLogsSinceId((int)uri.Id)));
                return;
            }

            // No id parameter, so send down the whole backup database
            long   databaseLastQueryId = -1;
            string databaseFileName    = DatabaseBackup.Backup(out databaseLastQueryId);

            // Verify database filename present
            if ((object)databaseFileName == null)
            {
                processor.WriteErrorHeader();
                return;
            }

            try
            {
                // Read in entire database file
                Stream stream      = new FileStream(ServerUtility.RootPath() + databaseFileName, FileMode.Open, FileAccess.Read);
                long   length      = stream.Length;
                int    startOffset = 0;

                // Handle the Range header to start from later in the file if connection interrupted
                if (processor.HttpHeaders.ContainsKey("Range"))
                {
                    string range = (string)processor.HttpHeaders["Range"];
                    string start = range.Split(new char[] { '-', '=' })[1];
                    logger.IfInfo("Connection retried.  Resuming from " + start);
                    startOffset = Convert.ToInt32(start);
                }

                // We send the last query id as a custom header
                IDictionary <string, string> customHeader = new Dictionary <string, string>();
                customHeader["WaveBox-LastQueryId"] = databaseLastQueryId.ToString();

                // Send the database file
                processor.WriteFile(stream, startOffset, length, "application/octet-stream", customHeader, true, new FileInfo(ServerUtility.RootPath() + databaseFileName).LastWriteTimeUtc);
                stream.Close();
            }
            catch
            {
                // Send JSON on error
                processor.WriteJson(new DatabaseResponse("Could not open backup database " + databaseFileName, null));
            }

            return;
        }
Example #3
0
 private void BackupDB_Click(object sender, RoutedEventArgs e)
 {
     DatabaseBackup.Backup();
 }