示例#1
0
        private string GetRenamedFile(string renameFilter, XciItem xci)
        {
            string renamed = string.Empty;

            renamed = renameFilter;
            renamed = renamed.Replace("{name}", xci.gameName);
            renamed = renamed.Replace("{titleid}", xci.titleId);
            renamed = renamed.Replace("{tid}", xci.titleId);
            renamed = renamed.Replace("{productcode}", xci.productCode);
            renamed = renamed.Replace("{prodcode}", xci.productCode);
            renamed = renamed.Replace("{size}", Helpers.XciHelper.ReadableFileSize(xci.gameSize));
            renamed = renamed.Replace("{developer}", xci.gameDeveloper);
            renamed = renamed.Replace("{dev}", xci.gameDeveloper);
            renamed = renamed.Replace("{trimmed}", xci.isXciTrimmed ? "trimmed" : "");
            renamed = renamed.Replace("{uniquecert}", xci.isUniqueCert ? "unique" : "");
            renamed = renamed.Replace("{cert}", xci.isUniqueCert ? "unique" : "");
            renamed = renamed.Replace("{revision}", xci.gameRevision);
            renamed = renamed.Replace("{gamerev}", xci.gameRevision);
            renamed = renamed.Replace("{rev}", xci.gameRevision);
            renamed = renamed.Replace("{masterkey}", xci.masterKeyRevision);
            renamed = renamed.Replace("{keyrev}", xci.masterKeyRevision);
            renamed = renamed.Replace("{keyrevision}", xci.masterKeyRevision);

            return(RemoveIllegalCharacters(renamed) + ".xci");
        }
示例#2
0
        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(); };
        }
示例#3
0
        private void BuildChildItems(XciItem parentItem)
        {
            var xci = parentItem.Xci;

            try
            {
                foreach (var xciPartitionType in Enum.GetValues <XciPartitionType>())
                {
                    try
                    {
                        if (!xci.HasPartition(xciPartitionType))
                        {
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        OnLoadingException(ex, parentItem);

                        var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToCheckIfXciPartitionExists.SafeFormat(ex.Message);
                        parentItem.Errors.Add(TREE_LOADING_CATEGORY, message);
                        _logger.LogError(ex, message);
                        continue;
                    }

                    XciPartition xciPartition;
                    try
                    {
                        xciPartition = xci.OpenPartition(xciPartitionType);
                    }
                    catch (Exception ex)
                    {
                        OnLoadingException(ex, parentItem);

                        var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToOpenXciPartition.SafeFormat(ex.Message);
                        parentItem.Errors.Add(TREE_LOADING_CATEGORY, message);
                        _logger.LogError(ex, message);
                        continue;
                    }

                    var xciPartitionItem = new XciPartitionItem(xciPartition, xciPartitionType, parentItem);
                    BuildChildItems(xciPartitionItem);

                    parentItem.ChildItems.Add(xciPartitionItem);
                }
            }
            catch (Exception ex)
            {
                OnLoadingException(ex, parentItem);

                var message = LocalizationManager.Instance.Current.Keys.LoadingError_FailedToLoadXciContent.SafeFormat(ex.Message);
                parentItem.Errors.Add(TREE_LOADING_CATEGORY, message);
                _logger.LogError(ex, message);
            }
        }
示例#4
0
        public XciItem LoadXci(string xciFilePath)
        {
            var keySet = _keySetProviderService.GetKeySet(_appSettings.AlwaysReloadKeysBeforeOpen);

            var localFile = new LocalFile(xciFilePath, OpenMode.Read);

            var fileStorage = new FileStorage(localFile);
            var xci         = new Xci(keySet, fileStorage);

            var xciItem = new XciItem(xci, System.IO.Path.GetFileName(xciFilePath), localFile, keySet);

            BuildChildItems(xciItem);
            return(xciItem);
        }
            public FileOverview CreateXciOverview(XciItem xciItem)
            {
                // NOTE: the secure partition of an XCI is equivalent to an NSP
                var securePartitionItem = xciItem.ChildItems.FirstOrDefault(partition => partition.XciPartitionType == XciPartitionType.Secure);

                var fileOverview = new FileOverview(xciItem);

                if (securePartitionItem == null)
                {
                    var message = LocalizationManager.Instance.Current.Keys.LoadingError_XciSecurePartitionNotFound;
                    xciItem.Errors.Add(message);
                    _logger.LogError(message);
                    return(fileOverview);
                }

                return(FillOverview(fileOverview, securePartitionItem));
            }
示例#6
0
        private void buttonInfo_Click(object sender, EventArgs e)
        {
            formRenameHelper helper = new formRenameHelper();
            XciItem          xciItem;

            try {
                xciItem = renameItems.First().xci;
            } catch
            {
                xciItem                   = new XciItem(@"C:\FAKEPATH\000 - Mario Meets Jesus [trimmed] (EnFrDeLol).xci");
                xciItem.gameName          = "Mario Meets Jesus";
                xciItem.gameDeveloper     = "Not Nintendo";
                xciItem.isXciTrimmed      = true;
                xciItem.productCode       = "ABCDEF";
                xciItem.titleId           = "0123456789123456";
                xciItem.masterKeyRevision = "MasterKey 9(12.0.0.0)";
                xciItem.isUniqueCert      = true;
                xciItem.gameSize          = 123456789;
            }
            helper.SetupHelper(xciItem, this);
            helper.Show();
        }
示例#7
0
 public void SetupHelper(XciItem xci, formRenamer formRenamer)
 {
     this.formRenamer = formRenamer;
     this.xci         = xci;
     AddListBoxItem("{name}", xci.gameName);
     AddListBoxItem("{titleid}", xci.titleId);
     AddListBoxItem("{tid}", xci.titleId);
     AddListBoxItem("{productcode}", xci.productCode);
     AddListBoxItem("{prodcode}", xci.productCode);
     AddListBoxItem("{size}", Helpers.XciHelper.ReadableFileSize(xci.gameSize));
     AddListBoxItem("{developer}", xci.gameDeveloper);
     AddListBoxItem("{dev}", xci.gameDeveloper);
     AddListBoxItem("{trimmed}", xci.isXciTrimmed ? "trimmed" : "");
     AddListBoxItem("{uniquecert}", xci.isUniqueCert ? "unique" : "");
     AddListBoxItem("{cert}", xci.isUniqueCert ? "unique" : "");
     AddListBoxItem("{revision}", xci.gameRevision);
     AddListBoxItem("{gamerev}", xci.gameRevision);
     AddListBoxItem("{rev}", xci.gameRevision);
     AddListBoxItem("{masterkey}", xci.masterKeyRevision);
     AddListBoxItem("{keyrev}", xci.masterKeyRevision);
     AddListBoxItem("{keyrevision}", xci.masterKeyRevision);
     listSelect.SelectedIndex = 0;
 }
示例#8
0
 public RenameItem(string filePath, string renamePath, XciItem xci)
 {
     this.filePath   = filePath;
     this.renamePath = renamePath;
     this.xci        = xci;
 }
示例#9
0
 public XciItemViewModel(XciItem xciItem, IServiceProvider serviceProvider)
     : base(xciItem, serviceProvider)
 {
 }
示例#10
0
        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);
        }
示例#11
0
        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;
        }
示例#12
0
        private void UpdateToolMenus()
        {
            //happens on right click to ContextMenu.
            //Update the ContextMenu's text items

            XciLocation destination = new XciLocation();
            XciLocation source      = new XciLocation();

            if (Helpers.Settings.config.defaultView == XciLocation.PC)
            {
                destination = XciLocation.SD;
                source      = XciLocation.PC;
            }
            else
            {
                destination = XciLocation.PC;
                source      = XciLocation.SD;
            }

            if (IsListIndexUsable(true))
            {
                ToolStripMenuItem toolStripMenu = (ToolStripMenuItem)contextMenuStrip.Items[0];
                gameManagementToolStripMenuItem.Enabled = true;
                contextMenuStrip.Enabled = true;

                copyToolStripMenuItem.Text   = $"Copy to {destination}";
                moveToolStripMenuItem.Text   = $"Move to {destination}";
                deleteToolStripMenuItem.Text = $"Delete from {source}";

                XciItem selected = (XciItem)olvList.SelectedObject;
                if (olvList.SelectedIndices.Count > 1)
                {
                    trimGameToolStripMenuItem.Text              = $"Trim {olvList.SelectedIndices.Count} Games";
                    copyToolStripMenuItem.Text                  = $"Copy {olvList.SelectedIndices.Count} Games to {destination}";
                    moveToolStripMenuItem.Text                  = $"Move {olvList.SelectedIndices.Count} Games to {destination}";
                    deleteToolStripMenuItem.Text                = $"Delete {olvList.SelectedIndices.Count} Games from {source}";
                    showInXCIExplorerToolStripMenuItem.Text     = $"Show {olvList.SelectedIndices.Count} Games in XCI Explorer";
                    showInWindowsExplorerToolStripMenuItem.Text = $"Show {olvList.SelectedIndices.Count} Games in Windows Explorer";
                    showXCICertificateToolStripMenuItem.Text    = $"Show {olvList.SelectedIndices.Count} XCI Certificates";
                }
                else
                {
                    trimGameToolStripMenuItem.Text              = $"Trim {selected.gameName}";
                    copyToolStripMenuItem.Text                  = $"Copy {selected.gameName} to {destination}";
                    moveToolStripMenuItem.Text                  = $"Move {selected.gameName} to {destination}";
                    deleteToolStripMenuItem.Text                = $"Delete {selected.gameName} from {source}";
                    showInXCIExplorerToolStripMenuItem.Text     = $"Show {selected.gameName} in XCI Explorer";
                    showInWindowsExplorerToolStripMenuItem.Text = $"Show {selected.gameName} in Windows Explorer";
                    showXCICertificateToolStripMenuItem.Text    = $"Show {selected.gameName} XCI Certificate";
                }

                contextMenuStrip.Items[2].Text = trimGameToolStripMenuItem.Text;
                contextMenuStrip.Items[4].Text = showXCICertificateToolStripMenuItem.Text;
                contextMenuStrip.Items[5].Text = showInXCIExplorerToolStripMenuItem.Text;
                contextMenuStrip.Items[6].Text = showInWindowsExplorerToolStripMenuItem.Text;

                toolStripMenu.DropDownItems[0].Text = copyToolStripMenuItem.Text;
                toolStripMenu.DropDownItems[1].Text = moveToolStripMenuItem.Text;
                toolStripMenu.DropDownItems[2].Text = deleteToolStripMenuItem.Text;
            }
            else
            {
                gameManagementToolStripMenuItem.Enabled = false;
                contextMenuStrip.Enabled = false;
            }
        }
 public FileOverview Load(XciItem xciItem)
 {
     return(new FileOverviewLoaderInternal(_logger).CreateXciOverview(xciItem));
 }