-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from OliBomby/dev
Dev Update 1.6.7.0
- Loading branch information
Showing
35 changed files
with
382 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Mapping Tools/Classes/Exceptions/BeatmapIncompatibleException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace Mapping_Tools.Classes.Exceptions { | ||
public class BeatmapIncompatibleException : Exception { | ||
public static readonly string BeatmapIncompatibleText = "This beatmap is incompatible with this operation."; | ||
|
||
public BeatmapIncompatibleException() : base(BeatmapIncompatibleText) { } | ||
|
||
public BeatmapIncompatibleException(string message) : base(message) { } | ||
|
||
public BeatmapIncompatibleException(string message, Exception innerException) : base(message, innerException) { } | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
Mapping Tools/Classes/SnappingTools/PrefferencesManager.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using Mapping_Tools.Classes.BeatmapHelper; | ||
using Mapping_Tools.Classes.Exceptions; | ||
|
||
namespace Mapping_Tools.Classes.SystemTools { | ||
public static class BackupManager { | ||
public static bool SaveMapBackup(string fileToCopy, bool forced = false, string customFileName = "", string backupCode = "") { | ||
if (!SettingsManager.GetMakeBackups() && !forced) | ||
return false; | ||
|
||
DateTime now = DateTime.Now; | ||
string destinationDirectory = SettingsManager.GetBackupsPath(); | ||
try { | ||
var name = now.ToString("yyyy-MM-dd HH-mm-ss") + "_" + backupCode + "__" + | ||
(string.IsNullOrEmpty(customFileName) ? Path.GetFileName(fileToCopy) : customFileName); | ||
|
||
File.Copy(fileToCopy, | ||
Path.Combine(destinationDirectory, name), | ||
true); | ||
|
||
// Delete old files if the number of backup files are over the limit | ||
foreach (var fi in new DirectoryInfo(SettingsManager.GetBackupsPath()).GetFiles().OrderByDescending(x => x.CreationTime).Skip(SettingsManager.Settings.MaxBackupFiles)) | ||
fi.Delete(); | ||
|
||
return true; | ||
} catch (Exception ex) { | ||
ex.Show(); | ||
return false; | ||
} | ||
} | ||
|
||
public static bool SaveMapBackup(string[] filesToCopy, bool forced = false, string backupCode = "") { | ||
bool result = true; | ||
foreach (string fileToCopy in filesToCopy) { | ||
result = SaveMapBackup(fileToCopy, forced, backupCode: backupCode); | ||
if (!result) | ||
break; | ||
} | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Copies a backup to replace a beatmap at the destination path. | ||
/// </summary> | ||
/// <param name="backupPath">Path to the backup map.</param> | ||
/// <param name="destination">Path to the destination map.</param> | ||
/// <param name="allowDifferentFilename">If false, this method throws an exception when the backup and the destination have mismatching beatmap metadata.</param> | ||
public static void LoadMapBackup(string backupPath, string destination, bool allowDifferentFilename = false) { | ||
var backupEditor = new BeatmapEditor(backupPath); | ||
var destinationEditor = new BeatmapEditor(destination); | ||
|
||
var backupFilename = backupEditor.Beatmap.GetFileName(); | ||
var destinationFilename = destinationEditor.Beatmap.GetFileName(); | ||
|
||
if (!allowDifferentFilename && !string.Equals(backupFilename, destinationFilename)) { | ||
throw new BeatmapIncompatibleException($"The backup and the destination beatmap have mismatching metadata.\n{backupFilename}\n{destinationFilename}"); | ||
} | ||
|
||
File.Copy(backupPath, destination, true); | ||
} | ||
|
||
public static void QuickUndo() { | ||
try { | ||
var path = IOHelper.GetCurrentBeatmap(); | ||
var backupFile = new DirectoryInfo(SettingsManager.GetBackupsPath()).GetFiles().OrderByDescending(x => x.CreationTime).FirstOrDefault(); | ||
if (backupFile != null) { | ||
try { | ||
LoadMapBackup(backupFile.FullName, path, false); | ||
} catch (BeatmapIncompatibleException ex) { | ||
ex.Show(); | ||
var result = MessageBox.Show("Do you want to load the backup anyways?", "Load backup", | ||
MessageBoxButton.YesNo); | ||
if (result == MessageBoxResult.Yes) { | ||
LoadMapBackup(backupFile.FullName, path, true); | ||
} else { | ||
return; | ||
} | ||
} | ||
Task.Factory.StartNew(() => MainWindow.MessageQueue.Enqueue("Backup successfully loaded!")); | ||
|
||
if (SettingsManager.Settings.AutoReload) { | ||
ListenerManager.ForceReloadEditor(); | ||
} | ||
} | ||
} catch (Exception ex) { | ||
ex.Show(); | ||
} | ||
} | ||
} | ||
} |
124 changes: 0 additions & 124 deletions
124
Mapping Tools/Classes/SystemTools/CustomSaveFileDialog.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.