public Pack(PackCollection collection, DirectoryInfo dataDirectory, PackIdentifier id) { if (dataDirectory == null) { throw new ArgumentNullException("dataDirectory"); } if (!dataDirectory.Exists) { throw new DirectoryNotFoundException(); } Collection = collection; DataDirectory = dataDirectory; this.Id = id; var indexPath = Path.Combine(DataDirectory.FullName, id.Expansion, string.Format(IndexFileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number)); var index2Path = Path.Combine(DataDirectory.FullName, id.Expansion, string.Format(Index2FileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number)); if (IOFile.Exists(indexPath)) { Source = new IndexSource(this, new Index(id, indexPath)); } else if (IOFile.Exists(index2Path)) { Source = new Index2Source(this, new Index2(id, index2Path)); } else { throw new FileNotFoundException(); } }
/// <summary> /// Update to the current version. /// </summary> /// <param name="detectDataChanges">Boolean indicating whether the update should also look for changes in data.</param> /// <param name="progress">Optional object to which update progress is reported.</param> /// <returns>Returns the <see cref="UpdateReport" /> containing all changes.</returns> /// <exception cref="InvalidOperationException">Definition is up-to-date.</exception> public UpdateReport Update(bool detectDataChanges, IProgress<UpdateProgress> progress = null) { if (DefinitionVersion == GameVersion) throw new InvalidOperationException(); var previousVersion = DefinitionVersion; var exdPackId = new PackIdentifier("exd", PackIdentifier.DefaultExpansion, 0); var exdPack = Packs.GetPack(exdPackId); var exdOldKeepInMemory = exdPack.KeepInMemory; exdPack.KeepInMemory = true; string tempPath = null; UpdateReport report; try { using (var zip = new ZipFile(StateFile.FullName, ZipEncoding)) { tempPath = ExtractPacks(zip, previousVersion); var previousPack = new PackCollection(Path.Combine(tempPath, previousVersion)); previousPack.GetPack(exdPackId).KeepInMemory = true; var previousDefinition = ReadDefinition(zip); var updater = new RelationUpdater(previousPack, previousDefinition, Packs, GameVersion, progress); var changes = updater.Update(detectDataChanges); report = new UpdateReport(previousVersion, GameVersion, changes); var definition = updater.Updated; StorePacks(zip); StoreDefinition(zip, definition, DefinitionFile); StoreDefinition(zip, definition, string.Format("{0}/{1}", definition.Version, DefinitionFile)); StoreReport(zip, report); zip.Save(); GameData.Definition = definition; GameData.Definition.Compile(); } } finally { if (exdPack != null) exdPack.KeepInMemory = exdOldKeepInMemory; if (tempPath != null) { try { Directory.Delete(tempPath, true); } catch { Console.Error.WriteLine("Failed to delete temporary directory {0}.", tempPath); } } } return report; }
public Pack(PackCollection collection, string dataPath, PackIdentifier id) : this(collection, new DirectoryInfo(dataPath), id) { }
/// <summary> /// Initializes a new instance of the <see cref="ARealmReversed" /> class. /// </summary> /// <param name="gameDirectory">Directory of the game installation.</param> /// <param name="storeFile">File used for storing definitions and history.</param> /// <param name="language">Initial language to use.</param> /// <param name="libraFile">Location of the Libra Eorzea database file, or <c>null</c> if it should not be used.</param> public ARealmReversed(DirectoryInfo gameDirectory, FileInfo storeFile, Language language, FileInfo libraFile) { _GameDirectory = gameDirectory; _Packs = new PackCollection(Path.Combine(gameDirectory.FullName, "game", "sqpack")); _GameData = new XivCollection(Packs, libraFile) { ActiveLanguage = language }; _GameVersion = File.ReadAllText(Path.Combine(gameDirectory.FullName, "game", "ffxivgame.ver")); _StateFile = storeFile; using (var zipFile = new ZipFile(StateFile.FullName, ZipEncoding)) { if (zipFile.ContainsEntry(VersionFile)) { RelationDefinition fsDef = null, zipDef = null; DateTime fsMod = DateTime.MinValue, zipMod = DateTime.MinValue; if (!TryGetDefinitionVersion(zipFile, GameVersion, out zipDef, out zipMod)) zipDef = ReadDefinition(zipFile, DefinitionFile, out zipMod); if (!TryGetDefinitionFromFileSystem(out fsDef, out fsMod)) fsDef = null; if (fsDef != null && fsMod > zipMod) { fsDef.Version = GameVersion; _GameData.Definition = fsDef; StoreDefinition(zipFile, fsDef, DefinitionFile); zipFile.Save(); } else _GameData.Definition = zipDef; } else _GameData.Definition = Setup(zipFile); } _GameData.Definition.Compile(); }