public static string GetOverridePath(string relativePath, string basePath = "") { try { if (string.IsNullOrWhiteSpace(relativePath)) { return(null); } // Replace alt directory separator with standard directory separator string filename = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); // Combine base path and folder path string folder = Path.Combine(basePath, Path.GetDirectoryName(filename)); // Add override folder at deepest folder level if not already included in folder path if (!folder.EndsWith(OverrideFolder, StringComparison.OrdinalIgnoreCase)) { folder = Path.Combine(folder, OverrideFolder); } // Resolve folder path and combine with filename return(Path.Combine(SettingsDataProvider.ResolveFolder(folder), Path.GetFileName(filename))); } catch (Exception ex) { log.Error(string.Format("Error determining full path for relative path [{0}]", relativePath), ex); } return(null); }
private void OpenPath(string path = null) { try { log.InfoFormat("Opening folder {0}", path); Process.Start("explorer.exe", SettingsDataProvider.ResolveFolder(path)); } catch (Exception ex) { log.Error(string.Format("Error opening folder: {0}", path), ex); } }
/// <summary> /// Builds and returns the extract path for the given Trove base path and zip entry /// </summary> private string GetZipEntryExtractPath(string basePath, ZipArchiveEntry entry, ref int errorCount) { string folder = GetZipEntryExtractFolder(basePath, entry, ref errorCount); if (string.IsNullOrEmpty(folder)) { return(null); } // Resolve folder path and combine with zip entry filename return(Path.Combine(SettingsDataProvider.ResolveFolder(Path.Combine(basePath, folder)), entry.Name)); }
private void ExtractArchives(IEnumerable <string> folders) { var loc = TroveLocation.PrimaryLocation; if (loc == null) { log.Info("No primary Trove location set: please update your settings before using the Extract Archives tool"); return; } string extractFolder = SettingsDataProvider.ResolveFolder(ExtractedPath); if (extractFolder.StartsWith(loc.LocationPath, StringComparison.OrdinalIgnoreCase)) { extractFolder = extractFolder.Remove(0, loc.LocationPath.Length + (loc.LocationPath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? 0 : 1)); } RunCommand(folders.ToList(), string.Format("-tool extractarchive \"{{0}}\" \"{0}\\{{0}}\"", extractFolder), 0); }
private string GetTmodFilePath(TroveLocation loc) { string modsFolder = SettingsDataProvider.ResolveFolder(Path.Combine(loc.LocationPath, ModsFolder)); return(Path.Combine(modsFolder, string.Format("{0}.tmod", SettingsDataProvider.GetSafeFilename(ModTitle)))); }
public static void ExtractTmod(string file, string folder, bool createOverrideFolders, bool createYaml, Action <double> updateProgress) { var buffer = new byte[1048576]; var properties = new Dictionary <string, string>(); var archiveEntries = new List <ArchiveIndexEntry>(); ulong headerSize = 0; using (var stream = File.OpenRead(file)) { using (var reader = new MyBinaryReader(stream)) { headerSize = ReadProperties(properties, stream, reader); // Read archive index entries (remainder of header) while ((ulong)stream.Position < headerSize) { var entry = new ArchiveIndexEntry(); entry.file = reader.ReadString(); entry.archiveIndex = reader.Read7BitEncodedInt(); entry.byteOffset = reader.Read7BitEncodedInt(); entry.size = reader.Read7BitEncodedInt(); entry.hash = reader.Read7BitEncodedInt(); archiveEntries.Add(entry); } int offset = 0, byteRead = 0; double count = 0; if (stream.Position != (long)headerSize) { stream.Position = (long)headerSize; } using (InflaterInputStream decompressionStream = new InflaterInputStream(stream)) { foreach (var entry in archiveEntries.OrderBy(e => e.byteOffset)) { updateProgress(count / archiveEntries.Count * 100d); log.InfoFormat("Extracting {0}", entry.file); string extractPath = Path.Combine(folder, entry.file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)); if (createOverrideFolders) { extractPath = Path.Combine(Path.GetDirectoryName(extractPath), TroveMod.OverrideFolder, Path.GetFileName(extractPath)); } SettingsDataProvider.ResolveFolder(Path.GetDirectoryName(extractPath)); // Advance data position to the next entry offset if needed while (offset < entry.byteOffset && byteRead != -1) { byteRead = decompressionStream.ReadByte(); offset++; } offset += SaveBytes(extractPath, stream, decompressionStream, Convert.ToInt64(headerSize) + Convert.ToInt64(entry.byteOffset), entry.size, buffer); } } } } try { if (createYaml) { string title = properties.ContainsKey(TitleValue) ? properties[TitleValue] : Path.GetFileNameWithoutExtension(file); string yamlPath = Path.Combine(folder, SettingsDataProvider.GetSafeFilename(title) + ".yaml"); log.InfoFormat("Generating YAML file: {0}", yamlPath); ModDetails details = new ModDetails() { Author = properties[AuthorValue], Title = properties[TitleValue], Notes = properties[NotesValue], PreviewPath = properties[PreviewPathValue], Files = archiveEntries.Select(e => e.file).ToList() }; if (properties.ContainsKey(TagsValue)) { string tags = properties[TagsValue]; if (!string.IsNullOrWhiteSpace(tags)) { details.Tags = tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } } details.SaveYamlFile(yamlPath); } } catch (Exception ex) { log.Error("Error generating YAML file", ex); } log.InfoFormat("Completed extracting files from {0}", file); }