}// ----------------------------------------- /// <summary> /// Array of files selected or NULL /// </summary> /// <param name="id">An ID previously set with prepareDialogFileLoad()</param> /// <param name="dir">Start in this directory</param> /// <param name="multi">Select multiple files</param> public static string[] fileLoadDialog(string id = "all", string dir = null, bool multi = false) { #if DEBUG if (fileOpenD == null) { LOG.log("ERROR: you must call prepareDialogFileLoad() to init"); return(null); } #endif if (dir != null) { fileOpenD.InitialDirectory = dir; } fileOpenD.Filter = fileDialogDict[id]; fileOpenD.Multiselect = multi; fileOpenD.CheckFileExists = true; fileOpenD.CheckPathExists = true; var res = fileOpenD.ShowDialog(); if (res == DialogResult.OK) { if (multi) { return(fileOpenD.FileNames); } else { return new[] { fileOpenD.FileName } }; } return(null); }// -----------------------------------------
}// ----------------------------------------- // -- // Display some info about the CD and tracks public void debugInfo() { LOG.log(this); LOG.line(); foreach (var tt in tracks) { LOG.log(tt); } LOG.line(); }// -----------------------------------------
}// ----------------------------------------- // -- // Call this on the destructor of forms you attach a box public static void detachTextBox() { if(textBoxTrace!=null) { LOG.log("Detaching"); Debug.Listeners.Remove(textBoxTrace); textBoxTrace.Dispose(); textBoxTrace = null; } }// -----------------------------------------
/// <summary> /// Prepare the Open File Dialog and add a filter to the filter pool for quick retrieval /// /// </summary> /// <param name="id"></param> /// <param name="filter">"ARC files (*.arc)|*.arc|All files (*.*)|*.*" Check inside for more </param> public static void fileLoadDialogPrepare(string id = null, string filter = null) { if (id == null) { id = "all"; } if (filter == null) { filter = "All files (*.*)|*.*"; } // Filter Examples:: // "ARC files (*.arc)|*.arc|All files (*.*)|*.*" // "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*" if (fileDialogDict == null) { fileDialogDict = new Dictionary <string, string>(); } if (!fileDialogDict.ContainsKey(id)) { fileDialogDict.Add(id, filter); } if (fileOpenD == null) { fileOpenD = new OpenFileDialog(); fileOpenD.AutoUpgradeEnabled = true; fileOpenD.AddExtension = true; fileOpenD.DereferenceLinks = true; fileOpenD.RestoreDirectory = true; // Remember the last directory used in the current session } LOG.log("+ FileLoadDialog init, {0}, {1}", id, filter); }// -----------------------------------------
}// ----------------------------------------- /// <summary> /// Load a descriptor file /// The CD title is read from the .CUE filename /// Also checks if files declared inside the .CUE exist or not /// </summary> /// <param name="file">Filename to load [.cue]</param> /// <returns>Success ( read the ERROR Property )</returns> public bool load(string file) { if (!File.Exists(file)) { ERROR = "File:" + file + "does not exist"; return(false); } // Vars init loadedFile_path = file; loadedFile_dir = Path.GetDirectoryName(loadedFile_path); loadedFile_ext = Path.GetExtension(loadedFile_path).ToLower().Trim('.'); // This is redudant.. if (!SUPPORTED_FORMATS.Contains(loadedFile_ext)) { ERROR = "File Type is not supported.- Supported formats : " + SUPPORTED_FORMATS.ToString(); return(false); } try { loadedFile = File.ReadAllLines(file); } catch (IOException) { ERROR = "There was an I/O problem loading the file"; return(false); } // Init vars CD_TOTAL_SIZE = 0; CD_TITLE = "untitled CD"; SECTOR_SIZE = 0; CD_TYPE = null; tracks = new List <CueTrack>(); openTrack = null; openFile = null; // Try to capture the CD TITLE from the CUE filename Match m1 = Regex.Match(loadedFile_path, @"([^\/\\]*)\.(?:" + SUPPORTED_FORMATS + @")$", RegexOptions.IgnoreCase); if (m1.Success) { CD_TITLE = m1.Groups[1].Value; } // Start Parsing the file based on it's type Func <string, int> parser; switch (loadedFile_ext) { case "cue": parser = cue_parser; break; case "ccd": parser = ccd_parser; break; default: parser = cue_parser; break; } // Parser :: for (int c = 0; c < loadedFile.Length; c++) { loadedFile[c] = loadedFile[c].Trim(); // Trim whitespaces if (loadedFile[c].Length == 0) { continue; // Skip blank lines } if (loadedFile[c] == "\n") { continue; } if (parser(loadedFile[c]) == 0) { ERROR = String.Format("Parse Error at line[{0}] : {1}", c + 1, ERROR); return(false); } } // -- POST PARSE CHECK :: if (tracks.Count == 0) { ERROR = "No Tracks in the CUE file"; return(false); } getCDTypeFromTracks(); // :: Some Debug Info LOG.log("[CUEREADER] : Loading : `{0}`", loadedFile_path); LOG.log("[CUEREADER] : Title : `{0}`, Type: `{1}`, NumberOfTracks:{2}", CD_TITLE, CD_TYPE, tracks.Count); LOG.indent(1); // -- if (loadedFile_ext == "ccd") { // TODO: CCD } // :: Go through each and every track, regardless if multitrack or not, // Check for every single one of the files if exist or not // Also count the number of file images to figure out `multifilecd` int cc = 0; // Number of tracks with DiskFiles found foreach (var tr in tracks) { if (tr.indexes.Count == 0) { ERROR = "Track [" + tr.trackNo + "] has no indexes defined"; return(false); } if (tr.trackFile == null) { continue; } cc++; tr.workingFile = Path.Combine(loadedFile_dir, tr.trackFile); // Check the diskfiles if (!File.Exists(tr.workingFile)) { ERROR = "Image \"" + tr.trackFile + "\" does not exist"; return(false); } // Get Sizes var finfo = new FileInfo(Path.Combine(loadedFile_dir, tr.trackFile)); tr.byteSize = (int)finfo.Length; // it can't be more than 800MB, so it's safe tr.sectorSize = (int)Math.Ceiling((double)(tr.byteSize / SECTOR_SIZE)); // -- if (tr.sectorSize <= 0) { // Rare but worth checking ERROR = "DiskFile " + tr.trackFile + " is currupt"; return(false); } CD_TOTAL_SIZE += tr.byteSize; } // -- end each track // :: POST PARSE CALCULATIONS AND CHECKS :: // - Is it MultiTrack with MultiFiles? if (cc == tracks.Count && cc > 1) { LOG.log("+ MULTI-FILE Image CD"); MULTIFILE = true; // Need to set sectorStart at each tracks; calculateTracksSectorStart(); } else if (cc == 1) { LOG.log("+ SINGLE-FILE Image CD"); MULTIFILE = false; // In case an single was found but not at the first track: if (tracks[0].trackFile == null) { ERROR = "First track must declare an image file"; return(false); } var imageSectorSize = tracks[0].sectorSize; //Calculate tracks, starting from the end, backwards to 0 var c = tracks.Count - 1; //Calculate last track manually, out of the loop tracks[c].calculateStart(); tracks[c].sectorSize = imageSectorSize - tracks[c].sectorStart; while (--c >= 0) { tracks[c].calculateStart(); tracks[c].sectorSize = tracks[c + 1].sectorStart - tracks[c].sectorStart; } calculateTracksByteSize(); } else if (cc == 0) { ERROR = "There are no image files declared in the sheet."; return(false); } else { // Rare, and I don't know if anything does this ERROR = "Multiple Image sheets are restricted to one Track per Image only"; return(false); } LOG.log("+ Total CD SIZE : {0}", CD_TOTAL_SIZE); foreach (var tt in tracks) { LOG.log(tt); } LOG.line(); LOG.indent(0); return(true); }// -----------------------------------------