private void MapEntryToFomodOption(List <Tuple <FomodFile, ModOption> > map, Entry entry, ModOption archiveModOption) { string entryPath = entry.GetPath(); string fomodBasePath = archiveModOption.BaseInstallerPath; if (fomodBasePath.Length > 0) { entryPath = entryPath.Replace(fomodBasePath, ""); } foreach (Tuple <FomodFile, ModOption> mapping in map) { FomodFile fileNode = mapping.Item1; ModOption option = mapping.Item2; if (fileNode.MatchesPath(entryPath)) { string mappedPath = fileNode.MappedPath(entryPath); if (mappedPath == "") { continue; } if (option.Assets.IndexOf(mappedPath) > -1) { continue; } option.Assets.Add(mappedPath); option.Size += (long)entry.Size; // enqueue jobs for analyzing archives and plugins MapEntryToOption(entry, option, archiveModOption); } } }
public string ExtractToTemp(string srcFile) { string ret; PermissionsManager.CurrentPermissions.Assert(); if (!ContainsFile(srcFile)) { throw new FileNotFoundException("File doesn't exist in fomod", srcFile); } var tmpFN = Path.GetTempFileName(); if ((m_arcCacheFile != null) && m_arcCacheFile.ContainsFile(GetPrefixAdjustedPath(srcFile))) { m_arcCacheFile.ExtractTo(GetPrefixAdjustedPath(srcFile), tmpFN); ret = tmpFN; } else { FomodFile.ExtractTo(GetPrefixAdjustedPath(srcFile), tmpFN); ret = tmpFN; } return(ret); }
/// <summary> /// Gets the contents of the specified file. /// </summary> /// <remarks> /// This method accounts for the <see cref="PathPrefix" />. /// </remarks> /// <param name="p_strPath">The path of the file whose contents are to be retrieved.</param> /// <returns>The contents of the specified file.</returns> public byte[] GetFileContents(string p_strPath) { if ((m_arcCacheFile != null) && m_arcCacheFile.ContainsFile(GetPrefixAdjustedPath(p_strPath))) { return(m_arcCacheFile.GetFileContents(GetPrefixAdjustedPath(p_strPath))); } return(FomodFile.GetFileContents(GetPrefixAdjustedPath(p_strPath))); }
/// <summary> /// Deletes the specified file. /// </summary> /// <remarks> /// This method accounts for the <see cref="PathPrefix" />. /// </remarks> /// <param name="p_strPath">The path of the file to delete.</param> protected void DeleteFile(string p_strPath) { if (!FomodFile.ReadOnly) { FomodFile.DeleteFile(GetPrefixAdjustedPath(p_strPath)); } if ((m_arcCacheFile != null) && m_arcCacheFile.ContainsFile(GetPrefixAdjustedPath(p_strPath))) { m_arcCacheFile.DeleteFile(GetPrefixAdjustedPath(p_strPath)); } }
/// <summary> /// Replaces the specified file with the given text. /// </summary> /// <remarks> /// This method accounts for the <see cref="PathPrefix" />. /// </remarks> /// <param name="p_strPath">The path of the file to replace.</param> /// <param name="p_strData">The new file text.</param> protected void ReplaceFile(string p_strPath, string p_strData) { if (!FomodFile.ReadOnly) { FomodFile.ReplaceFile(GetPrefixAdjustedPath(p_strPath), p_strData); } if ((m_arcCacheFile != null) && (m_arcCacheFile.ContainsFile(GetPrefixAdjustedPath(p_strPath)) || FomodFile.ReadOnly)) { m_arcCacheFile.ReplaceFile(GetPrefixAdjustedPath(p_strPath), p_strData); } }
/// <summary> /// Determines if the FOMod contains the given file. /// </summary> /// <remarks> /// This method accounts for the <see cref="PathPrefix" />. /// </remarks> /// <param name="p_strPath">The filename whose existence in the FOMod is to be determined.</param> /// <returns><lang langref="true" /> if the specified file is in the FOMod; <lang langref="false" /> otherwise.</returns> public bool ContainsFile(string p_strPath) { var strPath = p_strPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); strPath = strPath.Trim(Path.DirectorySeparatorChar); if (m_dicMovedArchiveFiles.ContainsKey(strPath)) { return(true); } if (FomodFile.ContainsFile(GetPrefixAdjustedPath(strPath))) { return(true); } return((m_arcCacheFile != null) && m_arcCacheFile.ContainsFile(GetPrefixAdjustedPath(strPath))); }
/// <summary> /// Retrieves the list of files in this FOMod. /// </summary> /// <remarks> /// This method accounts for the <see cref="PathPrefix" />. /// </remarks> /// <returns>The list of files in this FOMod.</returns> public List <string> GetFileList() { PermissionsManager.CurrentPermissions.Assert(); var lstFiles = new List <string>(); var intTrimLength = (PathPrefix.Length == 0) ? 0 : PathPrefix.Length + 1; foreach (var strFile in FomodFile.GetFiles(null)) { if (strFile.StartsWith(PathPrefix, StringComparison.InvariantCultureIgnoreCase)) { var strAdjustedFileName = strFile.Remove(0, intTrimLength); if (!strAdjustedFileName.StartsWith("fomod", StringComparison.OrdinalIgnoreCase)) { lstFiles.Add(strAdjustedFileName); } } } foreach (var strFile in m_dicMovedArchiveFiles.Keys) { lstFiles.Add(strFile); } return(lstFiles); }
/// <summary> /// This finds where in the archive the FOMod file structure begins. /// </summary> /// <remarks> /// This methods finds the path prefix to the folder containing the core files and folders of the FOMod. If /// there are any files that are above the core folder, than they are given new file names inside the /// core folder. /// </remarks> /// <seealso cref="PathPrefix" /> protected void FindPathPrefix() { m_dicMovedArchiveFiles.Clear(); var strSourcePath = "/"; //this code removes any top-level folders until it finds esp/esm/bsa, or the top-level folder // is a fomod/textures/meshes/music/shaders/video/facegen/menus/lodsettings/lsdata/sound folder. var directories = FomodFile.GetDirectories(strSourcePath); while (directories.Length == 1 && ((FomodFile.GetFiles(strSourcePath, "*.esp").Length == 0 && FomodFile.GetFiles(strSourcePath, "*.esm").Length == 0 && FomodFile.GetFiles(strSourcePath, "*.bsa").Length == 0) || Path.GetFileName(directories[0]).Equals("data", StringComparison.InvariantCultureIgnoreCase))) { directories = directories[0].Split(Path.DirectorySeparatorChar); var name = directories[directories.Length - 1].ToLowerInvariant(); if (!StopFolders.Contains(name)) { foreach (var file in FomodFile.GetFiles(strSourcePath)) { var strNewFileName = Path.GetFileName(file); for (var i = 1; m_dicMovedArchiveFiles.ContainsKey(strNewFileName); i++) { strNewFileName = Path.GetFileNameWithoutExtension(file) + " " + i + Path.GetExtension(file); } m_dicMovedArchiveFiles[strNewFileName] = file; } strSourcePath = Path.Combine(strSourcePath, name); directories = FomodFile.GetDirectories(strSourcePath); } else { break; } } PathPrefix = strSourcePath.Trim('/'); }
/// <summary> /// Ends a read-only transaction. /// </summary> /// <remarks> /// This takes the FOMod out of read-only mode. /// Read-only mode can greatly increase the speed at which multiple file are extracted. /// </remarks> public void EndReadOnlyTransaction() { FomodFile.EndReadOnlyTransaction(); }
/// <summary> /// Starts a read-only transaction. /// </summary> /// <remarks> /// This puts the FOMod into read-only mode. /// Read-only mode can greatly increase the speed at which multiple file are extracted. /// </remarks> public void BeginReadOnlyTransaction() { FomodFile.BeginReadOnlyTransaction(); }
internal void Dispose() { FomodFile.Dispose(); }