mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-24 04:53:08 +00:00
2acd1c5d21
Remove old cybergadget temp folder (interrupt is no longer used, now using Cache), fix/modify current methods for a more maintainable method. If GameFreak changes the filename, it'd only have to be changed in one place.
70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace PKHeX
|
|
{
|
|
public partial class Util
|
|
{
|
|
internal static string GetTempFolder()
|
|
{
|
|
return Path.Combine(Path.GetTempPath(), "3DSSE");
|
|
}
|
|
internal static string GetCacheFolder()
|
|
{
|
|
return Path.Combine(GetBackupLocation(), "cache");
|
|
}
|
|
internal static string GetRegistryValue(string key)
|
|
{
|
|
Microsoft.Win32.RegistryKey currentUser = Microsoft.Win32.Registry.CurrentUser;
|
|
Microsoft.Win32.RegistryKey key3 = currentUser.OpenSubKey(GetRegistryBase());
|
|
if (key3 == null)
|
|
return null;
|
|
|
|
string str = key3.GetValue(key) as string;
|
|
key3.Close();
|
|
currentUser.Close();
|
|
return str;
|
|
}
|
|
internal static string GetRegistryBase()
|
|
{
|
|
return @"SOFTWARE\CYBER Gadget\3DSSaveEditor";
|
|
}
|
|
internal static string GetBackupLocation()
|
|
{
|
|
string registryValue = GetRegistryValue("Location");
|
|
if (!string.IsNullOrEmpty(registryValue))
|
|
{
|
|
Directory.CreateDirectory(registryValue);
|
|
return registryValue;
|
|
}
|
|
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "3DSSaveBank");
|
|
Directory.CreateDirectory(path);
|
|
return path;
|
|
}
|
|
internal static string get3DSLocation()
|
|
{
|
|
try
|
|
{
|
|
string[] DriveList = Environment.GetLogicalDrives();
|
|
for (int i = 1; i < DriveList.Length; i++) // Skip first drive (some users still have floppy drives and would chew up time!)
|
|
{
|
|
string potentialPath = Path.Combine(DriveList[i], "Nintendo 3DS");
|
|
if (Directory.Exists(potentialPath))
|
|
return potentialPath;
|
|
}
|
|
}
|
|
catch { }
|
|
return null;
|
|
}
|
|
internal static string CleanFileName(string fileName)
|
|
{
|
|
return Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty));
|
|
}
|
|
internal static string TrimFromZero(string input)
|
|
{
|
|
int index = input.IndexOf('\0');
|
|
return index < 0 ? input : input.Substring(0, index);
|
|
}
|
|
}
|
|
}
|