public ArchiveSettingsScriptLoader(Func <ZipArchive, string, string> callback, ZipArchive archive, ModCollection parentCollection, InfoFile infoFile) { this.callback = callback; this.archive = archive; this.parentCollection = parentCollection; this.infoFile = infoFile; }
private ModFile(FileSystemInfo file, InfoFile infoFile, bool isFile, bool enabled, BitmapImage thumbnail) { this.file = file; InfoFile = infoFile; this.isFile = isFile; Enabled = enabled; Thumbnail = thumbnail; }
/// <summary> /// Tries to deserialize a given stream into an info file object. /// </summary> /// <param name="stream">The stream to deserialize.</param> /// <param name="infoFile">Out. The deserialized info file if the operation was successful.</param> /// <returns>Returns true if deserialization succeeded, otherwise false.</returns> private static bool TryDeserializeInfoFileFromStream(Stream stream, out InfoFile infoFile) { try { infoFile = InfoFile.FromJsonStream(stream); return(infoFile.IsValid); } catch (Exception ex) { App.Instance.WriteExceptionLog(ex); infoFile = null; return(false); } }
/// <summary> /// Determines if an archive file is a valid mod. /// </summary> /// <param name="archiveFile">The archive file to check.</param> /// <param name="infoFile">Out. The mods info file.</param> /// <param name="hasUid">Specifies if the file name contains a UID.</param> /// <returns>Returns true if the specified file is a valid mod, otherwise false.</returns> private static bool ArchiveFileValid(FileInfo archiveFile, out InfoFile infoFile, out bool enabled, bool hasUid) { infoFile = null; string fileName; GameCompatibleVersion fileVersion; if (!TryParseModName(archiveFile.NameWithoutExtension(), archiveFile.Extension, out fileName, out fileVersion, out enabled, hasUid)) { return(false); } if (TryReadInfoFileFromArchive(archiveFile, out infoFile)) { return((infoFile.Name == fileName) && (infoFile.Version == fileVersion)); } else { return(false); } }
/// <summary> /// Tries to read an info file from a directory. /// </summary> /// <param name="directory">The directory to read fromn.</param> /// <param name="infoFile">Out. The info file that has been read.</param> /// <returns>Returns true if an info file could be read from the directory, otherwise false.</returns> private static bool TryReadInfoFileFromDirectory(DirectoryInfo directory, out InfoFile infoFile) { infoFile = null; try { var file = directory.EnumerateFiles("info.json").FirstOrDefault(); if (file == null) { return(false); } using (var stream = file.OpenRead()) return(TryDeserializeInfoFileFromStream(stream, out infoFile) && infoFile.IsValid); } catch (Exception ex) { App.Instance.WriteExceptionLog(ex); return(false); } }
/// <summary> /// Tries to read an info file from an archive. /// </summary> /// <param name="archiveFile">The archive to read from.</param> /// <param name="infoFile">Out. The info file that has been read.</param> /// <returns>Returns true if an info file could be read from the archive, otherwise false.</returns> private static bool TryReadInfoFileFromArchive(FileInfo archiveFile, out InfoFile infoFile) { infoFile = null; try { using (var archive = ZipFile.OpenRead(archiveFile.FullName)) { var entry = archive.Entries.FirstOrDefault(e => (e.Name == "info.json") && (e.FullName.Count(c => c == '/') == 1)); if (entry == null) { return(false); } using (var stream = entry.Open()) return(TryDeserializeInfoFileFromStream(stream, out infoFile) && infoFile.IsValid); } } catch (Exception ex) { App.Instance.WriteExceptionLog(ex); return(false); } }
private static void ShowModExistsMessage(InfoFile infoFile) { MessageBox.Show(string.Format(App.Instance.GetLocalizedMessage("ModExists", MessageType.Information), infoFile.FriendlyName), App.Instance.GetLocalizedMessageTitle("ModExists", MessageType.Information), MessageBoxButton.OK, MessageBoxImage.Information); }
public DirectorySettingsScriptLoader(Func <string, string> callback, ModCollection parentCollection, InfoFile infoFile) { this.callback = callback; this.parentCollection = parentCollection; this.infoFile = infoFile; }