public string ExecuteScript(CUEToolsScript script) { if (!script.builtin) return ExecuteScript(script.code); switch (script.name) { case "default": return Go(); case "only if found": return ArVerify.ExceptionStatus != WebExceptionStatus.Success ? WriteReport() : Go(); case "repair": { UseCUEToolsDB("CUETools " + CUEToolsVersion, null, true, CTDBMetadataSearch.None); Action = CUEAction.Verify; if (CTDB.DBStatus != null) return CTDB.DBStatus; bool useAR = isUsingAccurateRip; isUsingAccurateRip = true; Go(); isUsingAccurateRip = useAR; List<CUEToolsSourceFile> choices = new List<CUEToolsSourceFile>(); foreach (DBEntry entry in CTDB.Entries) if (!entry.hasErrors || entry.canRecover) { StringBuilder sb = new StringBuilder(); if (entry.hasErrors) { sb.AppendFormat("Affected positions:\n"); for (int sec = 0; sec < entry.repair.AffectedSectorArray.Length; sec++) if (entry.repair.AffectedSectorArray[sec]) sb.AppendFormat("{0}\n", CDImageLayout.TimeToString((uint)sec)); } CUEToolsSourceFile choice = new CUEToolsSourceFile(entry.Status, new StringReader(sb.ToString())); choice.data = entry; choices.Add(choice); } CUEToolsSourceFile selectedEntry = ChooseFile(choices, null, true); if (selectedEntry == null) return CTDB.Status; CTDB.SelectedEntry = (DBEntry)selectedEntry.data; if (!CTDB.SelectedEntry.hasErrors) return CTDB.Status; isUsingCUEToolsDBFix = true; Action = CUEAction.Encode; return Go(); } case "fix offset": { if (ArVerify.ExceptionStatus != WebExceptionStatus.Success) return WriteReport(); WriteOffset = 0; Action = CUEAction.Verify; string status = Go(); uint tracksMatch; int bestOffset; FindBestOffset(Config.fixOffsetMinimumConfidence, !Config.fixOffsetToNearest, out tracksMatch, out bestOffset); if (tracksMatch * 100 >= Config.fixOffsetMinimumTracksPercent * TrackCount) { WriteOffset = bestOffset; Action = CUEAction.Encode; status = Go(); } return status; } case "encode if verified": { if (ArVerify.ExceptionStatus != WebExceptionStatus.Success) return WriteReport(); Action = CUEAction.Verify; string status = Go(); uint tracksMatch; int bestOffset; FindBestOffset(Config.encodeWhenConfidence, false, out tracksMatch, out bestOffset); if (tracksMatch * 100 >= Config.encodeWhenPercent * TrackCount && (!_config.encodeWhenZeroOffset || bestOffset == 0)) { Action = CUEAction.Encode; status = Go(); } return status; } } return "internal error"; }
private void listViewScripts_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Insert: { CUEToolsScript script; if (_config.scripts.TryGetValue("new", out script)) return; script = new CUEToolsScript("new", false, new CUEAction[] {}, ""); _config.scripts.Add("new", script); ListViewItem item = new ListViewItem(script.name); item.Tag = script; listViewScripts.Items.Add(item); item.BeginEdit(); break; } case Keys.Delete: { if (listViewScripts.SelectedItems.Count <= 0) return; CUEToolsScript script = (CUEToolsScript)listViewScripts.SelectedItems[0].Tag; if (script.builtin) return; _config.scripts.Remove(script.name); listViewScripts.Items.Remove(listViewScripts.SelectedItems[0]); break; } } }