2017-05-16 23:27:43 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
|
|
|
|
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"}
|
|
|
|
|
};
|
2017-06-18 01:37:19 +00:00
|
|
|
|
locs.AddRange(GetUserPaths());
|
|
|
|
|
locs.AddRange(Get3DSPaths());
|
2017-05-16 23:27:43 +00:00
|
|
|
|
locs.Add(new CustomFolderPath {Path = CyberGadgetUtil.GetCacheFolder(), DisplayText = "CGSE Cache"});
|
|
|
|
|
locs.Add(new CustomFolderPath {Path = CyberGadgetUtil.GetTempFolder(), DisplayText = "CGSE Temp"});
|
|
|
|
|
|
2017-10-05 23:01:16 +00:00
|
|
|
|
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);
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddButton(string name, string path)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
|
|
|
|
var button = new Button
|
|
|
|
|
{
|
|
|
|
|
Size = new Size { Height = 30, Width = 130 },
|
|
|
|
|
Text = name,
|
2017-09-30 05:58:25 +00:00
|
|
|
|
Name = $"B_{name}",
|
2017-05-16 23:27:43 +00:00
|
|
|
|
Enabled = new DirectoryInfo(path).Exists,
|
|
|
|
|
};
|
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(path))
|
2017-05-18 01:25:48 +00:00
|
|
|
|
{
|
2017-05-16 23:27:43 +00:00
|
|
|
|
Process.Start("explorer.exe", path);
|
2017-05-18 01:25:48 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
2017-05-16 23:27:43 +00:00
|
|
|
|
else
|
2018-04-07 04:23:09 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgFolderNotFound, path);
|
2017-05-16 23:27:43 +00:00
|
|
|
|
};
|
|
|
|
|
FLP_Buttons.Controls.Add(button);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<CustomFolderPath> GetUserPaths()
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2017-05-18 03:39:06 +00:00
|
|
|
|
string loc = Path.Combine(Main.WorkingDirectory, "savpaths.txt");
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
|
|
|
|
if (!File.Exists(loc))
|
2017-05-17 04:44:02 +00:00
|
|
|
|
yield break;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2018-02-20 07:34:07 +00:00
|
|
|
|
var lines = File.ReadLines(loc);
|
2017-05-17 04:44:02 +00:00
|
|
|
|
foreach (var line in lines)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2017-05-17 04:44:02 +00:00
|
|
|
|
var split = line.Split('\t');
|
|
|
|
|
if (split.Length == 2)
|
|
|
|
|
yield return new CustomFolderPath {DisplayText = split[0], Path = split[1]};
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
2017-05-17 04:44:02 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<CustomFolderPath> Get3DSPaths()
|
2017-05-17 04:44:02 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var path3DS = PathUtilWindows.Get3DSLocation();
|
2017-05-17 04:44:02 +00:00
|
|
|
|
var path = path3DS == null || !Directory.Exists(path3DS) ? @"C:\" : Path.GetPathRoot(path3DS);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in PathUtilWindows.Get3DSBackupPaths(path))
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2017-05-17 04:44:02 +00:00
|
|
|
|
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};
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 04:44:02 +00:00
|
|
|
|
private struct CustomFolderPath
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
|
|
|
|
public string Path;
|
|
|
|
|
public string DisplayText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|