Beispiel #1
0
        private ProcessFile addItem(SourceFile sourceFile)
        {
            ProcessFile pf = new ProcessFile()
            {
                SourceFile = sourceFile
            };
            ListViewItem li = new ListViewItem(pf.SourceFile.Name)
            {
                Tag = pf
            };

            for (int i = 0; i < lvw.Columns.Count - 1; i++)
            {
                li.SubItems.Add("");
            }

            if (this.HasDragDropItem)
            {
                lvw.Items.Clear();
            }

            lvw.Items.Add(li);
            return(pf);
        }
Beispiel #2
0
        private Task process(int mode, string regex, string path, ListViewItem[] items, Action <ListViewItem> startItem, Func <ListViewItem, bool> completedItem)
        {
            var guiSettings = new
            {
                Regex      = txtSettingsRegex.Text,
                SystemOnly = chkSettingsSystemFiles.Checked
            };

            return(Task.Run(() =>
            {
                foreach (ListViewItem item in items)
                {
                    ProcessFile pf = (ProcessFile)item.Tag;
                    SourceFile src = pf.SourceFile;
                    Converter nkitConvert = new Converter(src, false);
                    startItem(item);

                    try
                    {
                        nkitConvert.LogMessage += NkitConvert_LogMessage;

                        int fileTotalLen = src.TotalFiles.ToString().Length;

                        using (NDisc dx = new NDisc(nkitConvert, src.Name))
                        {
                            if (dx != null)
                            {
                                try
                                {
                                    switch (mode)
                                    {
                                    case 1:
                                        pf.Results = dx.ExtractRecoveryFiles();
                                        break;

                                    case 2:
                                        Regex rx = new Regex(guiSettings.Regex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                                        pf.Results = dx.ExtractFiles(
                                            /*test*/ f => (guiSettings.SystemOnly && (f.Type == ExtractedFileType.System || f.Type == ExtractedFileType.WiiDiscItem)) || (!guiSettings.SystemOnly && rx.IsMatch(string.Format("{0}/{1}", f.Path, f.Name))),
                                            /*extract*/ (s, f) => saveFile(path, pf.SourceFile.Name, f, s));
                                        break;

                                    case 3:
                                        pf.Results = dx.ExtractBasicInfo();
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    this.Invoke((MethodInvoker) delegate { addToLog(ex.Message); });
                                }
                                finally
                                {
                                }
                            }
                        }
                    }
                    finally
                    {
                        nkitConvert.LogMessage -= NkitConvert_LogMessage;
                    }
                    if (!completedItem(item))
                    {
                        break;
                    }
                }
            }));
        }
Beispiel #3
0
        private Task process(int convertMode, ListViewItem[] items, Action <ListViewItem> startItem, Func <ListViewItem, bool> completedItem)
        {
            //get the settings on the main thread to be used on another thread
            var guiSettings = new
            {
                SummaryLog                 = txtSettingsSummaryLog.Text,
                TempPath                   = txtSettingsTempPath.Text,
                CalculateHashes            = chkSettingsCalculateHashes.Checked,
                DeleteSource               = chkSettingsDeleteSource.Checked,
                EnableSummaryLog           = chkSettingsSummaryLog.Checked,
                FullVerify                 = chkSettingsFullVerify.Checked,
                NkitReencode               = chkSettingsReencodeNkit.Checked,
                NkitUpdatePartitionRemoval = chkSettingsRemoveUpdate.Checked,
                TestMode                   = chkSettingsTestMode.Checked,
                MaskRename                 = chkSettingsUseMasks.Checked,
                RecoveryMatchFailDelete    = chkSettingsRecoveryMatchFailDelete.Checked,
                Masks = _masks
            };

            return(Task.Run(() =>
            {
                foreach (ListViewItem item in items)
                {
                    bool exitLoop = false;
                    Converter nkitConvert = null;
                    ProcessFile pf = (ProcessFile)item.Tag;
                    try
                    {
                        SourceFile src = pf.SourceFile;
                        nkitConvert = new Converter(src, false);
                        startItem(item);
                        nkitConvert.Settings.SummaryLog = guiSettings.SummaryLog;
                        nkitConvert.Settings.TempPath = guiSettings.TempPath;
                        nkitConvert.Settings.CalculateHashes = guiSettings.CalculateHashes;
                        nkitConvert.Settings.DeleteSource = guiSettings.DeleteSource;
                        nkitConvert.Settings.EnableSummaryLog = guiSettings.EnableSummaryLog;
                        nkitConvert.Settings.FullVerify = guiSettings.FullVerify;
                        nkitConvert.Settings.NkitReencode = guiSettings.NkitReencode;
                        nkitConvert.Settings.NkitUpdatePartitionRemoval = guiSettings.NkitUpdatePartitionRemoval;
                        nkitConvert.Settings.TestMode = guiSettings.TestMode;
                        nkitConvert.Settings.MaskRename = guiSettings.MaskRename;
                        nkitConvert.Settings.RecoveryMatchFailDelete = guiSettings.RecoveryMatchFailDelete;

                        if (nkitConvert.Settings.DiscType == DiscType.GameCube)
                        {
                            nkitConvert.Settings.RedumpMatchRenameToMask = guiSettings.Masks["GameCube:RedumpMatchRenameToMask"];
                            nkitConvert.Settings.CustomMatchRenameToMask = guiSettings.Masks["GameCube:CustomMatchRenameToMask"];
                            nkitConvert.Settings.MatchFailRenameToMask = guiSettings.Masks["GameCube:MatchFailRenameToMask"];
                        }
                        else
                        {
                            nkitConvert.Settings.RedumpMatchRenameToMask = guiSettings.Masks["Wii:RedumpMatchRenameToMask"];
                            nkitConvert.Settings.CustomMatchRenameToMask = guiSettings.Masks["Wii:CustomMatchRenameToMask"];
                            nkitConvert.Settings.MatchFailRenameToMask = guiSettings.Masks["Wii:MatchFailRenameToMask"];
                        }

                        nkitConvert.LogMessage += NkitConvert_LogMessage;
                        nkitConvert.LogProgress += NkitConvert_LogProgress;
                        pf.Log = "";

                        switch (convertMode)
                        {
                        case 1:     //Recover to ISO
                            pf.Results = nkitConvert.RecoverToIso();
                            break;

                        case 2:     //Recover to Nkit.iso
                            nkitConvert.Settings.NkitFormat = NkitFormatType.Iso;
                            pf.Results = nkitConvert.RecoverToNkit();
                            break;

                        case 3:     //Recover to Nkit.gcz
                            nkitConvert.Settings.NkitFormat = NkitFormatType.Gcz;
                            pf.Results = nkitConvert.RecoverToNkit();
                            break;

                        case 4:     //Convert to .iso
                            pf.Results = nkitConvert.ConvertToIso();
                            break;

                        case 5:     //Convert to Nkit.iso
                            nkitConvert.Settings.NkitFormat = NkitFormatType.Iso;
                            pf.Results = nkitConvert.ConvertToNkit();
                            break;

                        case 6:     //Convert to Nkit.gcz
                            nkitConvert.Settings.NkitFormat = NkitFormatType.Gcz;
                            pf.Results = nkitConvert.ConvertToNkit();
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            HandledException hex = ex as HandledException;
                            if (hex == null && ex is AggregateException)
                            {
                                hex = (HandledException)((AggregateException)ex).InnerExceptions.FirstOrDefault(a => a is HandledException);
                            }

                            pf.Log += string.Format("Failed{0}-------{0}{1}", Environment.NewLine, hex != null ? hex.FriendlyErrorMessage : ex.Message);
                        }
                        catch { }
                    }
                    finally
                    {
                        exitLoop = !completedItem(item);
                        if (nkitConvert != null)
                        {
                            nkitConvert.LogMessage -= NkitConvert_LogMessage;
                            nkitConvert.LogProgress -= NkitConvert_LogProgress;
                        }
                    }
                    if (exitLoop)
                    {
                        break;
                    }
                }
            }));
        }