Exemplo n.º 1
0
        private static void GenerateBetterSaveMD5(List <string> lines)
        {
            var tempPath = System.IO.Path.Combine(MainWindow.AppDataPath, "temp.osu");

            if (!File.Exists(tempPath))
            {
                File.Create(tempPath).Dispose();
            }
            File.WriteAllLines(tempPath, lines);

            EditorReaderStuff.DontCoolSaveWhenMD5EqualsThisString = EditorReaderStuff.GetMD5FromPath(tempPath);
        }
Exemplo n.º 2
0
        public override void SaveFile()
        {
            var tempPath = System.IO.Path.Combine(MainWindow.AppDataPath, "temp.osu");

            if (!File.Exists(tempPath))
            {
                File.Create(tempPath).Dispose();
            }
            File.WriteAllLines(tempPath, TextFile.GetLines());

            EditorReaderStuff.DontCoolSaveWhenMD5EqualsThisString = EditorReaderStuff.GetMD5FromPath(tempPath);

            base.SaveFile();
        }
Exemplo n.º 3
0
        private void PeriodicBackupTimerOnTick(object sender, EventArgs e)
        {
            try {
                // Get the newest beatmap, save a temp version, get the hash and compare it to the previous hash, backup temp file
                var path = IOHelper.GetCurrentBeatmap();

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                // Don't make period backup if the editor is not open
                if (!EditorReaderStuff.IsEditorOpen())
                {
                    return;
                }

                EditorReader reader = null;
                try {
                    reader = EditorReaderStuff.GetFullEditorReader();
                } catch (Exception ex) {
                    Console.WriteLine(ex.MessageStackTrace());
                }

                var editor = EditorReaderStuff.GetNewestVersionOrNot(path, reader);

                // Save temp version
                var tempPath = Path.Combine(MainWindow.AppDataPath, "temp.osu");

                Editor.SaveFile(tempPath, editor.Beatmap.GetLines());

                // Get MD5 from temp file
                var currentMapHash = EditorReaderStuff.GetMD5FromPath(tempPath);

                // Comparing with previously made periodic backup
                if (currentMapHash == previousPeriodicBackupHash)
                {
                    return;
                }

                // Saving backup of the map
                BackupManager.SaveMapBackup(tempPath, true, Path.GetFileName(path), "PB");  // PB stands for Periodic Backup

                previousPeriodicBackupHash = currentMapHash;
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 4
0
        private static void OnChangedFsWatcher(object sender, FileSystemEventArgs e)
        {
            try {
                var currentPath = IOHelper.GetCurrentBeatmap();

                if (e.FullPath != currentPath)
                {
                    return;
                }

                var proc = System.Diagnostics.Process.GetProcessesByName("osu!").FirstOrDefault();
                if (proc != null)
                {
                    var oldHandle = GetForegroundWindow();
                    if (oldHandle != proc.MainWindowHandle)
                    {
                        return;
                    }
                }

                string hashString = "";
                try {
                    if (File.Exists(currentPath))
                    {
                        hashString = EditorReaderStuff.GetMD5FromPath(currentPath);
                    }
                }
                catch {
                    return;
                }

                if (EditorReaderStuff.DontCoolSaveWhenMD5EqualsThisString == hashString)
                {
                    return;
                }

                EditorReaderStuff.BetterSave();
            }
            catch (Exception ex) {
                MessageBox.Show("Failed to overwrite osu! save with BetterSave.");
                ex.Show();
            }
        }
Exemplo n.º 5
0
        private void PeriodicBackupTimerOnTick(object sender, EventArgs e)
        {
            try {
                // Get the newest beatmap, save a temp version, get the hash and compare it to the previous hash, backup temp file
                var path = IOHelper.GetCurrentBeatmap();

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                EditorReaderStuff.TryGetNewestVersion(path, out var editor);

                // Save temp version
                var tempPath = Path.Combine(MainWindow.AppDataPath, "temp.osu");

                if (!File.Exists(tempPath))
                {
                    File.Create(tempPath).Dispose();
                }

                File.WriteAllLines(tempPath, editor.Beatmap.GetLines());

                // Get MD5 from temp file
                var currentMapHash = EditorReaderStuff.GetMD5FromPath(tempPath);

                // Comparing with previously made periodic backup
                if (currentMapHash == previousPeriodicBackupHash)
                {
                    return;
                }

                // Saving backup of the map
                IOHelper.SaveMapBackup(tempPath, true, Path.GetFileName(path));

                previousPeriodicBackupHash = currentMapHash;
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }