mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-27 12:53:14 +00:00
1d4e815689
all common strings in forms used by multiple generations would rather rework the individual generation strings to be unnecessary with better interaction instead (if possible), as translating hundreds of limited exposure strings is a drag.
93 lines
3.1 KiB
C#
93 lines
3.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
namespace PKHeX.WinForms
|
|
{
|
|
public partial class SAV_FolderList : Form
|
|
{
|
|
public SAV_FolderList()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Preprogrammed folders
|
|
var locs = new List<CustomFolderPath>
|
|
{
|
|
new CustomFolderPath {Path = Main.BackupPath, DisplayText = "PKHeX Backups"}
|
|
};
|
|
locs.AddRange(GetUserPaths());
|
|
locs.AddRange(Get3DSPaths());
|
|
locs.Add(new CustomFolderPath {Path = CyberGadgetUtil.GetCacheFolder(), DisplayText = "CGSE Cache"});
|
|
locs.Add(new CustomFolderPath {Path = CyberGadgetUtil.GetTempFolder(), DisplayText = "CGSE Temp"});
|
|
|
|
var paths = locs.GroupBy(z => z.Path).Select(z => z.First())
|
|
.OrderByDescending(z => Directory.Exists(z.Path));
|
|
foreach (var loc in paths)
|
|
AddButton(loc.DisplayText, loc.Path);
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
}
|
|
|
|
private void AddButton(string name, string path)
|
|
{
|
|
var button = new Button
|
|
{
|
|
Size = new Size { Height = 30, Width = 130 },
|
|
Text = name,
|
|
Name = $"B_{name}",
|
|
Enabled = new DirectoryInfo(path).Exists,
|
|
};
|
|
button.Click += (s, e) =>
|
|
{
|
|
if (Directory.Exists(path))
|
|
{
|
|
Process.Start("explorer.exe", path);
|
|
Close();
|
|
}
|
|
else
|
|
WinFormsUtil.Alert(MsgFolderNotFound, path);
|
|
};
|
|
FLP_Buttons.Controls.Add(button);
|
|
}
|
|
|
|
private static IEnumerable<CustomFolderPath> GetUserPaths()
|
|
{
|
|
string loc = Path.Combine(Main.WorkingDirectory, "savpaths.txt");
|
|
|
|
if (!File.Exists(loc))
|
|
yield break;
|
|
|
|
var lines = File.ReadLines(loc);
|
|
foreach (var line in lines)
|
|
{
|
|
var split = line.Split('\t');
|
|
if (split.Length == 2)
|
|
yield return new CustomFolderPath {DisplayText = split[0], Path = split[1]};
|
|
}
|
|
}
|
|
private static IEnumerable<CustomFolderPath> Get3DSPaths()
|
|
{
|
|
var path3DS = PathUtilWindows.Get3DSLocation();
|
|
var path = path3DS == null || !Directory.Exists(path3DS) ? @"C:\" : Path.GetPathRoot(path3DS);
|
|
foreach (var z in PathUtilWindows.Get3DSBackupPaths(path))
|
|
{
|
|
var di = new DirectoryInfo(z);
|
|
var root = di.Root.Name;
|
|
var folder = di.Parent.Name;
|
|
if (root == folder)
|
|
folder = di.Name;
|
|
yield return new CustomFolderPath {Path = z, DisplayText = folder};
|
|
}
|
|
}
|
|
|
|
private struct CustomFolderPath
|
|
{
|
|
public string Path;
|
|
public string DisplayText;
|
|
}
|
|
}
|
|
}
|