public static bool TryLoad(FileInfo archiveFile, out FactorioFile file) { file = null; if (!archiveFile.Exists) { return(false); } try { using (var archive = ZipFile.OpenRead(archiveFile.FullName)) { if (!TryLoadVersion(archive, out var version)) { return(false); } if (!TryLoadBitness(archive, out bool is64Bit)) { return(false); } file = new FactorioFile(archiveFile, version, is64Bit); return(true); } } catch (Exception ex) { App.Instance.WriteExceptionLog(ex); return(false); } }
public static async Task <FactorioFolder> FromFileAsync(FactorioFile file, DirectoryInfo destination) { if (!destination.Exists) { destination.Create(); } await Task.Run(() => ZipFile.ExtractToDirectory(file.ArchiveFile.FullName, destination.FullName)); var dir = new DirectoryInfo(Path.Combine(destination.FullName, $"Factorio_{file.Version}")); if (!dir.Exists) { throw new InvalidOperationException("The given file contained invalid data."); } dir.MoveTo(Path.Combine(destination.FullName, GenerateUniqueName())); string executablePath = file.Is64Bit ? $@"bin\{Win64BinName}\factorio.exe" : $@"bin\{Win32BinName}\factorio.exe"; var executable = new FileInfo(Path.Combine(dir.FullName, executablePath)); return(new FactorioFolder(dir, executable, file.Version, file.Is64Bit)); }