/// <summary> /// Generates of a list of all the files inside the .idx .dat files from the Hellgate path. /// </summary> /// <returns>Result of the initialization. Occurance of an error will return false.</returns> private bool _LoadFileTable() { if (!Directory.Exists(HellgateDataPath)) { Console.WriteLine(@"Critical Error: HellgateDataPath data\ does not exist!"); return false; } List<String> idxPaths = new List<String>(); string[] query = IsVersionTestCenter ? Common.MPFiles : Common.SPFiles; foreach (String fileQuery in query) { idxPaths.AddRange(Directory.GetFiles(HellgateDataPath, fileQuery).Where(p => p.EndsWith(IndexFile.Extension) || p.EndsWith(HellgatePackFile.Extension))); } if (idxPaths.Count == 0) { Console.WriteLine("Error: No index files found at path: " + HellgateDataPath); return false; } foreach (String idxPath in idxPaths) { HellgateFile hellgateFile; String datFullPath; if (idxPath.EndsWith(IndexFile.Extension)) { hellgateFile = new IndexFile(idxPath); datFullPath = idxPath.Replace(IndexFile.Extension, ((IndexFile)hellgateFile).DatExtension); } else { hellgateFile = new HellgatePackFile(idxPath); datFullPath = idxPath.Replace(HellgatePackFile.Extension, ((HellgatePackFile)hellgateFile).DatExtension); } // if there is no accompanying .dat at all, then ignore .idx if (!File.Exists(datFullPath)) continue; // read in and parse index Debug.Write(String.Format("Loading pack file: {0}... ", Path.GetFileName(idxPath))); PackFile packFile = (PackFile)hellgateFile; try { byte[] fileBytes = File.ReadAllBytes(idxPath); hellgateFile.ParseFileBytes(fileBytes); #if DEBUG IndexFile indexFile = hellgateFile as IndexFile; if (indexFile != null) Debug.WriteLine("{0} files loaded.", indexFile.Files.Count); HellgatePackFile hgPackFile = hellgateFile as HellgatePackFile; if (hgPackFile != null) Debug.WriteLine("{0} files loaded.", hgPackFile.Files.Count); #endif } catch (Exception ex) { Console.WriteLine("Warning: Failed to read in index file: " + idxPath); Debug.WriteLine(ex); continue; } if (packFile.Count == 0) continue; IndexFiles.Add(packFile); _LoadIndexFile(packFile); } return FileEntries.Count != 0; }
/// <summary> /// Opens a TableForm based on the path to a Index or StringsFile. /// </summary> /// <param name="filePath">Path to the Index or StringsFile.</param> private void _OpenIndexFile(String filePath) { TableForm tableForm; PackFile packFile; if (filePath.EndsWith(IndexFile.Extension)) { packFile = new IndexFile(filePath); } else { packFile = new HellgatePackFile(filePath); } // Check if the form is already open. // If true, then activate the form. bool isOpen = _openTableForms.Where(tf => tf.FilePath == filePath).Any(); if (isOpen) { tableForm = _openTableForms.Where(tf => tf.FilePath == filePath).First(); if (tableForm.Created) { tableForm.Select(); return; } } // Try read the file. // If an exception is caught, log the error and inform the user. byte[] buffer; try { buffer = File.ReadAllBytes(filePath); } catch (Exception ex) { ExceptionLogger.LogException(ex, false); return; } // parse file try { packFile.ParseFileBytes(buffer); } catch (Exception ex) { ExceptionLogger.LogException(ex, false); return; } tableForm = new TableForm(packFile) { MdiParent = this, Text = Text + ": " + packFile.Path }; if (!_openTableForms.Contains(tableForm)) _openTableForms.Add(tableForm); tableForm.Show(); }
/// <summary> /// Generates of a list of all the files inside the .idx .dat files from the Hellgate path. /// </summary> /// <returns>Result of the initialization. Occurance of an error will return false.</returns> private bool _LoadFileTable() { if (!Directory.Exists(HellgateDataPath)) { Console.WriteLine(@"Critical Error: HellgateDataPath data\ does not exist!"); return(false); } List <String> idxPaths = new List <String>(); string[] query = IsVersionTestCenter ? Common.MPFiles : Common.SPFiles; foreach (String fileQuery in query) { idxPaths.AddRange(Directory.GetFiles(HellgateDataPath, fileQuery).Where(p => p.EndsWith(IndexFile.Extension) || p.EndsWith(HellgatePackFile.Extension))); } if (idxPaths.Count == 0) { Console.WriteLine("Error: No index files found at path: " + HellgateDataPath); return(false); } foreach (String idxPath in idxPaths) { HellgateFile hellgateFile; String datFullPath; if (idxPath.EndsWith(IndexFile.Extension)) { hellgateFile = new IndexFile(idxPath); datFullPath = idxPath.Replace(IndexFile.Extension, ((IndexFile)hellgateFile).DatExtension); } else { hellgateFile = new HellgatePackFile(idxPath); datFullPath = idxPath.Replace(HellgatePackFile.Extension, ((HellgatePackFile)hellgateFile).DatExtension); } // if there is no accompanying .dat at all, then ignore .idx if (!File.Exists(datFullPath)) { continue; } // read in and parse index Debug.Write(String.Format("Loading pack file: {0}... ", Path.GetFileName(idxPath))); PackFile packFile = (PackFile)hellgateFile; try { byte[] fileBytes = File.ReadAllBytes(idxPath); hellgateFile.ParseFileBytes(fileBytes); #if DEBUG IndexFile indexFile = hellgateFile as IndexFile; if (indexFile != null) { Debug.WriteLine("{0} files loaded.", indexFile.Files.Count); } HellgatePackFile hgPackFile = hellgateFile as HellgatePackFile; if (hgPackFile != null) { Debug.WriteLine("{0} files loaded.", hgPackFile.Files.Count); } #endif } catch (Exception ex) { Console.WriteLine("Warning: Failed to read in index file: " + idxPath); Debug.WriteLine(ex); continue; } if (packFile.Count == 0) { continue; } IndexFiles.Add(packFile); _LoadIndexFile(packFile); } return(FileEntries.Count != 0); }