private static IEnumerable <CustomFolderPath> GetSwitchPaths(IEnumerable <string> drives) { var pathNX = SaveDetection.GetSwitchLocation(drives); if (pathNX == null) { return(Enumerable.Empty <CustomFolderPath>()); } var root = Path.GetPathRoot(pathNX); var paths = SaveDetection.GetSwitchBackupPaths(root); return(paths.Select(z => new CustomFolderPath(z))); }
/// <summary> /// Opens a dialog to open a <see cref="SaveFile"/>, <see cref="PKM"/> file, or any other supported file. /// </summary> /// <param name="Extensions">Misc extensions of <see cref="PKM"/> files supported by the SAV.</param> /// <param name="path">Output result path</param> /// <returns>Result of whether or not a file is to be loaded from the output path.</returns> public static bool OpenSAVPKMDialog(IEnumerable <string> Extensions, out string path) { string supported = string.Join(";", Extensions.Select(s => $"*.{s}").Concat(new[] { "*.pkm" })); OpenFileDialog ofd = new OpenFileDialog { Filter = "All Files|*.*" + $"|Supported Files (*.*)|main;*.bin;{supported};*.bak" + ExtraSaveExtensions + "|Save Files (*.sav)|main" + ExtraSaveExtensions + "|Decrypted PKM File (*.pkm)|" + supported + "|Binary File|*.bin" + "|Backup File|*.bak" }; // Detect main string cgse = ""; string pathCache = CyberGadgetUtil.GetCacheFolder(); if (Directory.Exists(pathCache)) { cgse = Path.Combine(pathCache); } string msg = null; var sav = SaveDetection.DetectSaveFile(Environment.GetLogicalDrives(), ref msg, cgse); if (sav == null && !string.IsNullOrWhiteSpace(msg)) { Error(msg); } if (sav != null) { ofd.FileName = sav.FileName; } if (ofd.ShowDialog() != DialogResult.OK) { path = null; return(false); } path = ofd.FileName; return(true); }
public SAV_FolderList(Action <SaveFile> openSaveFile) { InitializeComponent(); OpenSaveFile = openSaveFile; var drives = Environment.GetLogicalDrives(); Paths = GetPathList(drives); dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent); dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup); var recent = SaveDetection.GetSaveFiles(drives, false, Paths.Select(z => z.Path).Where(z => z != Main.BackupPath)); Recent = PopulateData(dgDataRecent, recent); var backup = SaveDetection.GetSaveFiles(drives, false, Main.BackupPath); Backup = PopulateData(dgDataBackup, backup); CB_FilterColumn.Items.Add(MsgAny); var dgv = Recent.Count >= 1 ? dgDataRecent : dgDataBackup; int count = dgv.ColumnCount; for (int i = 0; i < count; i++) { var text = dgv.Columns[i].HeaderText; CB_FilterColumn.Items.Add(text); var tempLabel = new Label { Name = "DGV_" + text, Text = text, Visible = false }; Controls.Add(tempLabel); TempTranslationLabels.Add(tempLabel); } CB_FilterColumn.SelectedIndex = 0; WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); // Update Translated headers for (int i = 0; i < TempTranslationLabels.Count; i++) { var text = TempTranslationLabels[i].Text; if (i < dgDataRecent.ColumnCount) { dgDataRecent.Columns[i].HeaderText = text; } if (i < dgDataBackup.ColumnCount) { dgDataBackup.Columns[i].HeaderText = text; } CB_FilterColumn.Items[i + 1] = text; } // Preprogrammed folders foreach (var loc in Paths) { AddButton(loc.DisplayText, loc.Path); } AddCustomizeButton(); dgDataRecent.DoubleBuffered(true); dgDataBackup.DoubleBuffered(true); CenterToParent(); }