mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:52:55 +08:00
User copy operation instead of move
This commit is contained in:
parent
49a03f1c06
commit
7a2020fd45
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -14,6 +15,14 @@ namespace osu.Game.IO
|
|||||||
private readonly GameHost host;
|
private readonly GameHost host;
|
||||||
private readonly StorageConfigManager storageConfig;
|
private readonly StorageConfigManager storageConfig;
|
||||||
|
|
||||||
|
internal static readonly string[] IGNORE_DIRECTORIES = { "cache" };
|
||||||
|
|
||||||
|
internal static readonly string[] IGNORE_FILES =
|
||||||
|
{
|
||||||
|
"framework.ini",
|
||||||
|
"storage.ini"
|
||||||
|
};
|
||||||
|
|
||||||
public OsuStorage(GameHost host)
|
public OsuStorage(GameHost host)
|
||||||
: base(host.Storage, string.Empty)
|
: base(host.Storage, string.Empty)
|
||||||
{
|
{
|
||||||
@ -43,20 +52,58 @@ namespace osu.Game.IO
|
|||||||
Directory.Delete(newLocation, true);
|
Directory.Delete(newLocation, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.Move(oldLocation, newLocation);
|
var source = new DirectoryInfo(oldLocation);
|
||||||
|
var destination = new DirectoryInfo(newLocation);
|
||||||
|
|
||||||
Directory.CreateDirectory(newLocation);
|
copyRecursive(source, destination);
|
||||||
// temporary
|
|
||||||
Directory.CreateDirectory(oldLocation);
|
|
||||||
|
|
||||||
// move back exceptions for now
|
|
||||||
Directory.Move(Path.Combine(newLocation, "cache"), Path.Combine(oldLocation, "cache"));
|
|
||||||
File.Move(Path.Combine(newLocation, "framework.ini"), Path.Combine(oldLocation, "framework.ini"));
|
|
||||||
|
|
||||||
ChangeTargetStorage(host.GetStorage(newLocation));
|
ChangeTargetStorage(host.GetStorage(newLocation));
|
||||||
|
|
||||||
storageConfig.Set(StorageConfig.FullPath, newLocation);
|
storageConfig.Set(StorageConfig.FullPath, newLocation);
|
||||||
storageConfig.Save();
|
storageConfig.Save();
|
||||||
|
|
||||||
|
deleteRecursive(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteRecursive(DirectoryInfo target, bool topLevelExcludes = true)
|
||||||
|
{
|
||||||
|
foreach (System.IO.FileInfo fi in target.GetFiles())
|
||||||
|
{
|
||||||
|
if (IGNORE_FILES.Contains(fi.Name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fi.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DirectoryInfo dir in target.GetDirectories())
|
||||||
|
{
|
||||||
|
if (IGNORE_DIRECTORIES.Contains(dir.Name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
dir.Delete(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true)
|
||||||
|
{
|
||||||
|
// based off example code https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo
|
||||||
|
Directory.CreateDirectory(destination.FullName);
|
||||||
|
|
||||||
|
foreach (System.IO.FileInfo fi in source.GetFiles())
|
||||||
|
{
|
||||||
|
if (IGNORE_FILES.Contains(fi.Name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fi.CopyTo(Path.Combine(destination.FullName, fi.Name), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DirectoryInfo dir in source.GetDirectories())
|
||||||
|
{
|
||||||
|
if (IGNORE_DIRECTORIES.Contains(dir.Name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
copyRecursive(dir, destination.CreateSubdirectory(dir.Name), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user