private void comboBoxDriveLetters_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxDriveLetters.SelectedIndex == 0) { sdDriveLetter = ""; return; } DriveInfo driveInfo = new DriveInfo(comboBoxDriveLetters.Text.Substring(0, 1)); List <string> info = new List <string>(); info.Add("VolumeLabel:\t" + driveInfo.VolumeLabel); info.Add("DriveType:\t" + driveInfo.DriveType); info.Add("DriveFormat:\t" + driveInfo.DriveFormat); info.Add("IsReady:\t\t" + driveInfo.IsReady); info.Add("TotalSize:\t\t" + XciHelper.ReadableFileSize(driveInfo.TotalSize)); info.Add("AvailFreeSpace:\t" + XciHelper.ReadableFileSize(driveInfo.AvailableFreeSpace)); info.Add("TotalFreeSpace:\t" + XciHelper.ReadableFileSize(driveInfo.TotalFreeSpace)); sdDriveLetter = driveInfo.RootDirectory.ToString(); textBoxDriveInfo.Clear(); foreach (var item in info) { textBoxDriveInfo.Text += item + Environment.NewLine; } }
protected override void WndProc(ref Message m) { try { if (m.Msg == WM_DEVICECHANGE) { DEV_BROADCAST_VOLUME vol = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME)); if ((m.WParam.ToInt32() == DBT_DEVICEARRIVAL) && (vol.dbcv_devicetype == DBT_DEVTYPVOLUME)) { if (Helpers.Settings.config.sdDriveLetter.Contains(DriveMaskToLetter(vol.dbcv_unitmask).ToString())) { locationToolStripComboBox.SelectedIndex = 1; XciHelper.LoadXcisInBackground(); UpdateSdInfo(); } } if ((m.WParam.ToInt32() == DBT_DEVICEREMOVALCOMPLETE) && (vol.dbcv_devicetype == DBT_DEVTYPVOLUME)) { if (Helpers.Settings.config.sdDriveLetter.Contains(DriveMaskToLetter(vol.dbcv_unitmask).ToString())) { locationToolStripComboBox.SelectedIndex = 0; XciHelper.LoadXcisInBackground(); UpdateSdInfo(); } } } base.WndProc(ref m); } catch { } }
public void SaveSettings() { //save the OLV state to olvState byte array (column positions, etc) Helpers.Settings.config.olvState = olvList.SaveState(); XciHelper.SaveXciCache(); Helpers.Settings.SaveSettings(); }
private void SetupDelegates() { textBoxFilter.TextChanged += delegate(object o, EventArgs e) { TextMatchFilter filter = TextMatchFilter.Contains(olvList, textBoxFilter.Text); olvList.AdditionalFilter = filter; UpdateToolStripLabel(); }; olvList.MouseClick += delegate(object s, MouseEventArgs e) { UpdateToolMenus(); if (e.Button == MouseButtons.Right) { contextMenuStrip.Show(e.X, e.Y); } }; gameManagementToolStripMenuItem.Click += delegate(object s, EventArgs e) { UpdateToolMenus(); }; olvList.MouseDoubleClick += delegate(object s, MouseEventArgs e) { XciItem xci = (XciItem)olvList.GetItem(olvList.SelectedIndex).RowObject; XciHelper.ShowXciExplorer(xci.xciFilePath); }; exitToolStripMenuItem.Click += delegate(object s, EventArgs e) { Application.Exit(); }; locationToolStripComboBox.SelectedIndexChanged += delegate(object s, EventArgs e) { Helpers.Settings.config.defaultView = (XciLocation)locationToolStripComboBox.SelectedIndex; XciHelper.RefreshList(); UpdateToolStripLabel(); }; aboutToolStripMenuItem.Click += delegate(object o, EventArgs e) { formAbout formAbout = new formAbout(); formAbout.Show(); }; this.FormClosing += delegate(object s, FormClosingEventArgs e) { SaveSettings(); }; this.ResizeEnd += delegate(object s, EventArgs e) { if (this.WindowState != FormWindowState.Maximized) { Helpers.Settings.config.formHeight = this.Height; Helpers.Settings.config.formWidth = this.Width; } }; cancelTransfersToolStripMenuItem.Click += delegate(object s, EventArgs e) { FileHelper.StopTransfers(); }; rebuildCachetoolStripMenuItem.Click += delegate(object s, EventArgs e) { XciHelper.RebuildCache(); }; refreshGamesListToolStripMenuItem.Click += delegate(object s, EventArgs e) { XciHelper.LoadXcisInBackground(); }; }
private void formMain_Load(object sender, EventArgs e) { XciHelper.formMain = this; FileHelper.formMain = this; this.Text += " " + Application.ProductVersion; if (!File.Exists("keys.txt")) { MessageBox.Show("Please make sure to put the keys.txt file in the same folder as SwitchGameManager.exe" + Environment.NewLine + "The program will now close.", "Keys.txt not found"); Application.Exit(); return; } SetupObjectListView(); SetupDelegates(); //Load the settings if (Helpers.Settings.LoadSettings() == false) { manageXciLocToolStripMenuItem_Click(null, null); } SetupFileSysWatcher(); locationToolStripComboBox.SelectedIndex = 0; //Setup the OLV with the saved state (if it was saved) if (Helpers.Settings.config.olvState != null) { olvList.RestoreState(Helpers.Settings.config.olvState); ProcessChangeIconSize(Helpers.Settings.config.listIconSize); } if (Helpers.Settings.config.formHeight > 0) { this.Height = Helpers.Settings.config.formHeight; } if (Helpers.Settings.config.formWidth > 0) { this.Width = Helpers.Settings.config.formWidth; } UpdateToolMenus(); XciHelper.LoadXcisInBackground(); /* todo * Check if Keys.txt exists, otherwise download it. Maybe procedurally generate the URL? brute force the key? * Add red X or green check for Game cert, either use a Resource img or system image? */ }
private bool TryRename(RenameItem item) { try { File.Move(item.filePath, item.renamePath); item.xci.uniqueId = XciHelper.GetXciIdentifier(item.renamePath); //TODO verify file was moved return(true); } catch (Exception ex) { item.renameException = ex; return(false); } }
private void manageXciLocToolStripMenuItem_Click(object sender, EventArgs e) { formFolderList form = new formFolderList(); DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { Helpers.Settings.config.localXciFolders = form.localFolders; Helpers.Settings.config.sdDriveLetter = form.sdDriveLetter; SetupFileSysWatcher(); XciHelper.LoadXcisInBackground(); //XciHelper.LoadXcis(); UpdateToolMenus(); } }
private void buttonRename_Click(object sender, EventArgs e) { buttonRename.Enabled = false; List <RenameItem> filtered = olvRenameList.FilteredObjects.Cast <RenameItem>().ToList(); for (int i = filtered.Count - 1; i >= 0; i--) { if (TryRename(filtered[i])) { olvRenameList.RemoveObject(filtered[i]); } else { columnError.IsVisible = true; olvRenameList.UpdateObject(filtered[i]); } } olvRenameList.RebuildColumns(); buttonRename.Enabled = true; XciHelper.LoadXcisInBackground(); }
public bool ProcessFileManagement(XciItem xci) { bool success = false; if (!Helpers.Settings.CheckForSdCard() && (xci.fileAction.action == FileAction.Copy || xci.fileAction.action == FileAction.Delete || xci.fileAction.action == FileAction.Move)) { return(false); } switch (xci.fileAction.action) { case FileAction.None: break; case FileAction.Copy: case FileAction.Move: FileHelper.TransferXci(xci); break; case FileAction.Delete: try { if (File.Exists(xci.xciFilePath)) { File.Delete(xci.xciFilePath); } if (!File.Exists(xci.xciFilePath)) { success = true; } xci.fileAction.actionCompleted = true; xci.fileAction.actionSuccess = success; XciHelper.UpdateXci(xci); return(success); } catch { } return(false); case FileAction.CompletelyDelete: List <XciItem> deleteItems = GetAllItemsByIdentifer(xci.uniqueId); for (int i = deleteItems.Count - 1; i >= 0; i--) { if (File.Exists(deleteItems[i].xciFilePath)) { File.Delete(deleteItems[i].xciFilePath); } if (!File.Exists(deleteItems[i].xciFilePath)) { success = true; } deleteItems[i].fileAction = Clone(xci.fileAction); deleteItems[i].fileAction.actionCompleted = true; deleteItems[i].fileAction.actionSuccess = success; UpdateXci(deleteItems[i]); } return(success); case FileAction.Trim: bool trim; if (xci.gameSize != xci.gameUsedSize) { trim = XciHelper.TrimXci(xci); if (trim) { UpdateToolStripLabel($"Successfully trimmed {xci.gameName}!"); } else { UpdateToolStripLabel($"Failed to trim {xci.gameName}!"); } xci.fileAction.actionCompleted = true; xci.fileAction.actionSuccess = true; //re-process the XCI //RefreshXciInBackground(xci); return(trim); } else { UpdateToolStripLabel($"{xci.gameName} is already trimmed!"); return(true); } case FileAction.ShowCert: XciHelper.ShowXciCert(xci); return(true); case FileAction.ShowXciInfo: if (!string.IsNullOrWhiteSpace(xci.xciFilePath)) { ShowXciExplorer(xci.xciFilePath); } break; case FileAction.ShowInExplorer: if (!File.Exists(xci.xciFilePath)) { UpdateToolStripLabel($"{xci.xciFilePath} could not be found!"); return(false); } Process.Start("explorer.exe", "/select, \"" + xci.xciFilePath + "\""); return(true); default: break; } return(true); }
private void ToolStripManagement(object sender, EventArgs e) { //use ProcessFileManagement //delete all copies //trim //show cert //show xciexplorer //show in explorer string message = string.Empty, action = string.Empty, source = string.Empty, destination = string.Empty; FileStruct fileAction = new FileStruct(); ToolStripItem clicked = sender as ToolStripItem; int toolIndex = olvList.ContextMenuStrip.Items.IndexOf(clicked); if (toolIndex < 0) { toolIndex = gameManagementToolStripMenuItem.DropDownItems.IndexOf(clicked); } if (toolIndex == 1) { fileAction.action = FileAction.CompletelyDelete; } if (toolIndex == 2) { fileAction.action = FileAction.Trim; } if (toolIndex == 3) { fileAction.action = FileAction.ShowRenameWindow; } if (toolIndex == 4) { fileAction.action = FileAction.ShowCert; } if (toolIndex == 5) { fileAction.action = FileAction.ShowXciInfo; } if (toolIndex == 6) { fileAction.action = FileAction.ShowInExplorer; } if (toolIndex == 7) { fileAction.action = FileAction.OpenOnTinfoilWeb; } if (Helpers.Settings.config.defaultView == XciLocation.PC) { fileAction.destination = XciLocation.SD; fileAction.source = XciLocation.PC; } else { fileAction.destination = XciLocation.PC; fileAction.source = XciLocation.SD; } switch (fileAction.action) { case FileAction.ShowRenameWindow: formRenamer renamer = new formRenamer(); List <XciItem> renameList = olvList.SelectedObjects.Cast <XciItem>().ToList(); renamer.PopulateList(renameList); renamer.Show(); return; case FileAction.ShowInExplorer: case FileAction.ShowCert: case FileAction.ShowXciInfo: List <XciItem> showInfo = olvList.SelectedObjects.Cast <XciItem>().ToList(); foreach (XciItem item in showInfo) { item.fileAction = Clone(fileAction); ProcessFileManagement(item); } return; case FileAction.OpenOnTinfoilWeb: List <XciItem> openWeb = olvList.SelectedObjects.Cast <XciItem>().ToList(); foreach (XciItem item in openWeb) { if (item.titleId != null || item.titleId.Length > 0) { System.Diagnostics.Process.Start("https://tinfoil.io/Title/" + item.titleId); } } return; default: break; } XciItem xci; int success = 0, failure = 0; action = Enum.GetName(typeof(FileAction), fileAction.action); if (fileAction.action == FileAction.CompletelyDelete) { action = "completely delete (from all locations)"; } if (olvList.SelectedIndices.Count > 1) { if (MessageBox.Show($"Are you sure you want to {action} {olvList.SelectedObjects.Count} games?", $"Confirm {action.ToUpperInvariant()}", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) { return; } List <XciItem> actionList = olvList.SelectedObjects.Cast <XciItem>().ToList(); foreach (XciItem obj in actionList) { xci = Clone(obj); xci.fileAction = Clone(fileAction); if (ProcessFileManagement(xci)) { success++; } else { failure++; } UpdateToolStripLabel($"{action.ToUpperInvariant()} results: Success: {success} Failed: {failure}"); if (fileAction.action == FileAction.Trim) { XciHelper.UpdateXci(xci); } } } else { xci = Clone((XciItem)olvList.GetItem(olvList.SelectedIndex).RowObject); xci.fileAction = fileAction; if (MessageBox.Show($"Are you sure you want to {action} {xci.gameName}?", $"Confirm {action.ToUpperInvariant()}", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) { return; } ProcessFileManagement(xci); if (fileAction.action == FileAction.Trim) { XciHelper.UpdateXci(xci); } } if (fileAction.action == FileAction.CompletelyDelete) { XciHelper.RefreshList(); } }
private void ToolStripFileManagement(object sender, EventArgs e) { XciItem xci; string message = string.Empty, action = string.Empty, source = string.Empty, destination = string.Empty; int success = 0, failure = 0; FileStruct fileAction = new FileStruct(); ToolStripItem clicked = sender as ToolStripItem; ToolStripMenuItem toolStripMenu = fileToolStripMenuItem; int toolIndex = toolStripMenu.DropDownItems.IndexOf(clicked); if (toolIndex < 0) { toolStripMenu = (ToolStripMenuItem)contextMenuStrip.Items[0]; toolIndex = toolStripMenu.DropDownItems.IndexOf(clicked); } Debug.Assert(toolIndex >= 0); if (!IsListIndexUsable()) { return; } if (toolIndex == 0) { fileAction.action = FileAction.Copy; } if (toolIndex == 1) { fileAction.action = FileAction.Move; } if (toolIndex == 2) { fileAction.action = FileAction.Delete; } //Refresh Game Info if (toolIndex == 3) { List <XciItem> filtered = olvList.SelectedObjects.Cast <XciItem>().ToList(); foreach (XciItem obj in filtered) { XciHelper.RefreshXciInBackground(obj); } return; } if (Helpers.Settings.config.defaultView == XciLocation.PC) { fileAction.destination = XciLocation.SD; fileAction.source = XciLocation.PC; } else { fileAction.destination = XciLocation.PC; fileAction.source = XciLocation.SD; } action = Enum.GetName(typeof(FileAction), fileAction.action); source = Enum.GetName(typeof(XciLocation), fileAction.source); destination = Enum.GetName(typeof(XciLocation), fileAction.destination); if (olvList.SelectedIndices.Count > 1) { List <XciItem> filtered = olvList.SelectedObjects.Cast <XciItem>().ToList(); double totalSize = filtered.Sum(x => x.gameSize); double sizeDiff; if (fileAction.action == FileAction.Move || fileAction.action == FileAction.Copy) { try { if ((double)sdInfo.AvailableFreeSpace <= totalSize) { sizeDiff = totalSize - (double)sdInfo.AvailableFreeSpace; MessageBox.Show($"Unable to copy games to SD! {Environment.NewLine} You need {ReadableFileSize(sizeDiff)} more space for this transfer!", "Unable To Transfer", MessageBoxButtons.OK); return; } } catch { } message = $"Are you sure you want to {action} {olvList.SelectedObjects.Count} games ({ReadableFileSize(totalSize)}) to {destination}?"; } if (fileAction.action == FileAction.Delete) { message = $"Are you sure you want to {action} {olvList.SelectedObjects.Count} games from {source}?"; } if (MessageBox.Show(message, $"Confirm {action.ToUpperInvariant()}", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) { return; } foreach (XciItem obj in filtered) { xci = Clone(obj); xci.fileAction = Clone(fileAction); if (ProcessFileManagement(xci)) { success++; } else { failure++; } } if (fileAction.action == FileAction.Copy || fileAction.action == FileAction.Move) { UpdateToolStripLabel($"Games queued for {action.ToUpperInvariant()}: {success}"); } else { UpdateToolStripLabel($"{action.ToUpperInvariant()} results: Success: {success} Failed: {failure}"); } } else { xci = (XciItem)olvList.GetItem(olvList.SelectedIndex).RowObject; if (fileAction.action == FileAction.Move || fileAction.action == FileAction.Copy) { message = $"Are you sure you want to {action} {xci.gameName} to {destination}?"; } if (fileAction.action == FileAction.Delete) { message = $"Are you sure you want to {action} {xci.gameName} from {source}?"; } if (MessageBox.Show(message, $"Confirm {action.ToUpperInvariant()}", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) { return; } xci.fileAction = fileAction; if (ProcessFileManagement(xci)) { UpdateToolStripLabel($"{action.ToUpperInvariant()} successful for {xci.gameName}"); } else { UpdateToolStripLabel($"{action.ToUpperInvariant()} failed for {xci.gameName}"); } } //XciHelper.LoadXcisInBackground(); }
private void SetupObjectListView() { SendMessage(textBoxFilter.Control.Handle, 0x1501, 1, "Filter Library.."); //initialize the image lists, big and small olvList.LargeImageList = new ImageList(); olvList.LargeImageList.ImageSize = new Size(128, 128); olvList.SmallImageList = new ImageList(); olvList.SmallImageList.ImageSize = new Size(64, 64); //setup the getters that determine how the list shows data/icons olvColumnGameSize.AspectGetter = delegate(object row) { XciItem xciInfo = (XciItem)row; return(xciInfo.gameSize); }; olvColumnGameSize.AspectToStringConverter = delegate(object row) { double sizeInBytes = (double)row; return(XciHelper.ReadableFileSize(sizeInBytes)); }; olvColumnGameUsedSize.AspectGetter = delegate(object row) { XciItem xciInfo = (XciItem)row; return(xciInfo.gameUsedSize); }; olvColumnGameUsedSize.AspectToStringConverter = delegate(object row) { double sizeInBytes = (double)row; return(XciHelper.ReadableFileSize(sizeInBytes)); }; olvColumnXciName.ImageGetter = delegate(object row) { XciItem xciInfo = (XciItem)row; String key = xciInfo.uniqueId; if (!this.olvList.LargeImageList.Images.ContainsKey(key)) { if (xciInfo.gameIcon != null) { this.olvList.SmallImageList.Images.Add(key, xciInfo.gameIcon); this.olvList.LargeImageList.Images.Add(key, xciInfo.gameIcon); } } return(key); }; /* * this.olvColumnisXciTrimmed.Renderer = new MappedImageRenderer(new Object[] { * true, Resources.trimmed * }); * * this.olvColumnLocalGame.Renderer = new MappedImageRenderer(new Object[] { * true, Resources.computer * }); * * this.olvColumnSdGame.Renderer = new MappedImageRenderer(new Object[] { * true, Resources.microsd * }); */ ToolStripMenuItem newMenuItem; ToolStripMenuItem subMenuItem; foreach (ToolStripMenuItem menuItem in gameManagementToolStripMenuItem.DropDownItems) { if (menuItem.DropDownItems.Count > 0) { newMenuItem = new ToolStripMenuItem(menuItem.Text); foreach (ToolStripMenuItem subItem in menuItem.DropDownItems) { subMenuItem = new ToolStripMenuItem(subItem.Text, null, onClick: ToolStripFileManagement); newMenuItem.DropDownItems.Add(subMenuItem); } } else { newMenuItem = new ToolStripMenuItem(menuItem.Text, null, onClick: ToolStripManagement); } contextMenuStrip.Items.Add(newMenuItem); } olvList.ContextMenuStrip = contextMenuStrip; }