Skip to content

Commit

Permalink
Merge pull request #103 from OliBomby/dev
Browse files Browse the repository at this point in the history
Dev Update 1.6.7.0
  • Loading branch information
OliBomby authored Jun 26, 2020
2 parents 739df98 + 6e8d2c0 commit aecb776
Show file tree
Hide file tree
Showing 35 changed files with 382 additions and 526 deletions.
6 changes: 2 additions & 4 deletions Mapping Tools/Classes/BeatmapHelper/Events/Break.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ public sealed override void SetLine(string line) {

EventType = values[0];

// This start time is usually 0 for backgrounds but lets parse it anyways
if (TryParseInt(values[1], out int startTime))
StartTime = startTime;
else throw new BeatmapParsingException("Failed to parse start time of break.", line);

// This start time is usually 0 for backgrounds but lets parse it anyways
if (TryParseInt(values[1], out int endTime))
if (TryParseInt(values[2], out int endTime))
EndTime = endTime;
else throw new BeatmapParsingException("Failed to parse start time of break.", line);
else throw new BeatmapParsingException("Failed to parse end time of break.", line);
}
}
}
48 changes: 45 additions & 3 deletions Mapping Tools/Classes/BeatmapHelper/HitObjectComparer.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
using System.Collections.Generic;
using System.Linq;

namespace Mapping_Tools.Classes.BeatmapHelper {
class HitObjectComparer : IEqualityComparer<HitObject> {
public bool CheckIsSelected { get; set; }
public bool CheckPosition { get; set; }
public bool CheckTime { get; set; }

public HitObjectComparer(bool checkIsSelected = false) {
public HitObjectComparer(bool checkIsSelected = false, bool checkPosition = true, bool checkTime = true) {
CheckIsSelected = checkIsSelected;
CheckPosition = checkPosition;
CheckTime = checkTime;
}

public bool Equals(HitObject x, HitObject y) {
return x.GetLine() == y.GetLine() &&
(!CheckIsSelected || x.IsSelected == y.IsSelected);
if (x == null && y == null)
return true;
if (x == null || y == null)
return false;
if (CheckIsSelected && x.IsSelected != y.IsSelected)
return false;
if (CheckPosition && x.Pos != y.Pos)
return false;
if (CheckTime && x.Time != y.Time)
return false;
if (!(x.Hitsounds == y.Hitsounds &&
x.Filename == y.Filename &&
x.SampleVolume == y.SampleVolume &&
x.CustomIndex == y.CustomIndex &&
x.AdditionSet == y.AdditionSet &&
x.SampleSet == y.SampleSet &&
x.NewCombo == y.NewCombo &&
x.ComboSkip == y.ComboSkip))
return false;
if (x.IsCircle && y.IsCircle) {
return true;
}
if (x.IsSlider && y.IsSlider) {
return x.SliderType == y.SliderType &&
(!CheckPosition || x.CurvePoints.SequenceEqual(y.CurvePoints)) &&
x.Repeat == y.Repeat &&
x.PixelLength == y.PixelLength &&
x.EdgeHitsounds.SequenceEqual(y.EdgeHitsounds) &&
x.EdgeSampleSets.SequenceEqual(y.EdgeSampleSets) &&
x.EdgeAdditionSets.SequenceEqual(y.EdgeAdditionSets);
}
if (x.IsSpinner && y.IsSpinner) {
return x.EndTime == y.EndTime;
}
if (x.IsHoldNote && y.IsHoldNote) {
return x.EndTime == y.EndTime;
}

return false;
}

public int GetHashCode(HitObject obj) {
Expand Down
13 changes: 13 additions & 0 deletions Mapping Tools/Classes/Exceptions/BeatmapIncompatibleException.cs
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 Mapping Tools/Classes/SnappingTools/PrefferencesManager.cs

This file was deleted.

94 changes: 94 additions & 0 deletions Mapping Tools/Classes/SystemTools/BackupManager.cs
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 Mapping Tools/Classes/SystemTools/CustomSaveFileDialog.cs

This file was deleted.

Loading

0 comments on commit aecb776

Please sign in to comment.