public static async Task <GameFileInfo> GenerateGameFileInfo(string file, string fileName, string outputFolder, string baseHttpLink, CancellationToken ct = default) { if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } if (!baseHttpLink.EndsWith("/")) { baseHttpLink += "/"; } var binFileName = $"{fileName.ToLower().GetHashCode():X4}.bin"; var outFileName = Path.Combine(outputFolder, binFileName); await L33TZipUtils.CompressFileAsL33TZipAsync(file, outFileName, ct); var fileCrc = await Crc32Utils.DoGetCrc32FromFile(file, ct); var fileLength = new FileInfo(file).Length; var externalLocation = Path.Combine(baseHttpLink, binFileName).Replace("\\", "/"); var outFileCrc = await Crc32Utils.DoGetCrc32FromFile(outFileName, ct); var outFileLength = new FileInfo(outFileName).Length; return(new GameFileInfo(fileName, fileCrc, fileLength, externalLocation, outFileCrc, outFileLength)); }
public static async Task <bool> RunFileCheck(string filePath, long fileSize, uint fileCrc32, #pragma warning disable IDE0034 // Simplifier l'expression 'default' CancellationToken ct = default(CancellationToken), #pragma warning restore IDE0034 // Simplifier l'expression 'default' IProgress <double> progress = null) { return(RunFileQuickCheck(filePath, fileSize) && fileCrc32 == await Crc32Utils.DoGetCrc32FromFile(filePath, ct, progress)); }
public override void Process(object obj) { FileInfo file = obj as FileInfo; UInt32 crc = Crc32Utils.CalculateCRC32(file); if (crcs.ContainsKey(crc)) { Logger.Write(Tokens.Info, "\n"); Logger.WriteLine(Tokens.Info, crcs[crc].FullName); Logger.WriteLine(Tokens.Info, file.FullName); } else { crcs.Add(crc, file); } }
private static async Task <GameFileInfo> GenerateGameFileInfo(string file, string fileName, string outputFolder, #pragma warning disable IDE0034 // Simplifier l'expression 'default' string baseHttpLink, CancellationToken ct = default(CancellationToken)) #pragma warning restore IDE0034 // Simplifier l'expression 'default' { if (!baseHttpLink.EndsWith("/")) { baseHttpLink += "/"; } var binFileName = $"{fileName.ToLower().GetHashCode():X4}.bin"; var outFileName = Path.Combine(outputFolder, binFileName); await L33TZipUtils.DoCreateL33TZipFile(file, outFileName, ct); var fileInfo = new GameFileInfo(fileName, await Crc32Utils.DoGetCrc32FromFile(file, ct), new FileInfo(file).Length, Path.Combine(baseHttpLink, binFileName).Replace("\\", "/"), await Crc32Utils.DoGetCrc32FromFile(outFileName, ct), new FileInfo(outFileName).Length); return(fileInfo); }
public static async Task EnsureValidGameFile(string gameFilePath, long expectedFileSize, uint expectedCrc32, CancellationToken ct = default, IProgress <double> progress = null) { var gameFileInfo = new FileInfo(gameFilePath); if (!gameFileInfo.Exists) { throw new Exception($"The game file {gameFilePath} does not exist"); } if (gameFileInfo.Length != expectedFileSize) { throw new Exception( $"The game file {gameFilePath} was expected to have a size of {expectedFileSize} but was {gameFileInfo.Length}"); } var gameFileCrc32 = await Crc32Utils.DoGetCrc32FromFile(gameFilePath, ct, progress); if (gameFileCrc32 != expectedCrc32) { throw new Exception( $"The game file {gameFilePath} was expected to have a crc32 {expectedCrc32} but was {gameFileCrc32}"); } }
public static async Task <bool> RunFileCheck(string gameFilePath, long expectedFileSize, uint expectedCrc32, CancellationToken ct = default, IProgress <double> progress = null) { return(RunFileQuickCheck(gameFilePath, expectedFileSize) && expectedCrc32 == await Crc32Utils.DoGetCrc32FromFile(gameFilePath, ct, progress)); }
private static bool RunFileCheck(string filePath, long fileSize, uint fileCrc32) { return(RunFileQuickCheck(filePath, fileSize) && Crc32Utils.RunCrc32FileCheck(filePath, fileCrc32)); }
private void Btn_RunEditor_Click(object sender, EventArgs e) { try { var pname = Process.GetProcessesByName("editor"); if (pname.Length > 0) { MsgBox.ShowMessage(@"Editor already running!"); return; } btn_Browse.Enabled = false; //Launch Game var path = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath) ? Program.UserConfig.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var spartanPath = Path.Combine(path, "Editor.exe"); if (!File.Exists(spartanPath)) { throw new FileNotFoundException("Editor.exe not found!", spartanPath); } //isSteam if (!Program.UserConfig.IsSteamVersion) { var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll"); if (File.Exists(steamApiDll)) { File.Delete(steamApiDll); } } // string lang; switch (Program.UserConfig.GameLanguage) { case GameLanguage.deDE: lang = "de-DE"; break; case GameLanguage.enUS: lang = "en-US"; break; case GameLanguage.esES: lang = "es-ES"; break; case GameLanguage.frFR: lang = "fr-FR"; break; case GameLanguage.itIT: lang = "it-IT"; break; case GameLanguage.zhCHT: lang = "zh-CHT"; break; default: throw new ArgumentOutOfRangeException(nameof(Program.UserConfig.GameLanguage), Program.UserConfig.GameLanguage, null); } //SymLink Profile Folder var profileDir = Path.Combine(Environment.GetEnvironmentVariable("userprofile")); var path1 = Path.Combine(profileDir, "Documents", "Age of Empires Online"); var path2 = Path.Combine(profileDir, "Documents", "Spartan"); if (!Directory.Exists(path2)) { Directory.CreateDirectory(path2); } if (Directory.Exists(path1) && (!Misc.IsSymLink(path1, Misc.SymLinkFlag.Directory) || !string.Equals(Misc.GetRealPath(path1), path2, StringComparison.OrdinalIgnoreCase))) { Directory.Delete(path1, true); Misc.CreateSymbolicLink(path1, path2, Misc.SymLinkFlag.Directory); } else { Misc.CreateSymbolicLink(path1, path2, Misc.SymLinkFlag.Directory); } //ExtractAiBarFiles var inputFile = Path.Combine(Program.UserConfig.GameFilesPath, "AI", "AI.bar"); if (!File.Exists(inputFile)) { throw new FileNotFoundException($"File '{inputFile}' not found!", inputFile); } var outputPath = Path.Combine(Program.UserConfig.GameFilesPath, "AI"); using (var fileStream = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var binReader = new BinaryReader(fileStream)) { binReader.BaseStream.Seek(284, SeekOrigin.Begin); var filesTableOffset = binReader.ReadUInt32(); binReader.BaseStream.Seek(filesTableOffset, SeekOrigin.Begin); var rootNameLength = binReader.ReadUInt32(); binReader.BaseStream.Seek(rootNameLength * 2, SeekOrigin.Current); var numberOfRootFiles = binReader.ReadUInt32(); for (uint i = 0; i < numberOfRootFiles; i++) { var offset = binReader.ReadInt32(); var fileSize = binReader.ReadInt32(); binReader.BaseStream.Seek(20, SeekOrigin.Current); var lengthFileName = binReader.ReadUInt32(); var fileName = Encoding.Unicode.GetString(binReader.ReadBytes((int)lengthFileName * 2)); var baseDir = Path.GetDirectoryName(fileName) ?? string.Empty; if (baseDir.ToLower().Contains("celeste")) { continue; } var position = binReader.BaseStream.Position; // binReader.BaseStream.Seek(offset, SeekOrigin.Begin); var bytes = binReader.ReadBytes(fileSize); binReader.BaseStream.Seek(position, SeekOrigin.Begin); var str = Encoding.Default.GetString(bytes); if (!str.ToLower().Contains("include \"aimain.xs\";")) { continue; } // var outFile = new FileInfo(Path.Combine(outputPath, fileName)); if (outFile.Exists) { if (outFile.Length == fileSize && Crc32Utils.GetCrc32File(outFile.FullName) == Crc32Utils.GetCrc32FromBytes(bytes)) { continue; } outFile.Delete(); } // var dir = new DirectoryInfo(Path.Combine(outputPath, baseDir)); if (!dir.Exists) { dir.Create(); } if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { dir.Attributes |= FileAttributes.Hidden; } // File.WriteAllBytes(outFile.FullName, bytes); if ((outFile.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly) { outFile.Attributes |= FileAttributes.ReadOnly; } } } } // Process.Start( new ProcessStartInfo(spartanPath, $"LauncherLang={lang} LauncherLocale=1033") { WorkingDirectory = path }); WindowState = FormWindowState.Minimized; Close(); } catch (Exception ex) { MsgBox.ShowMessage( $"Error: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); btn_Browse.Enabled = true; } }
private void ClickLoad() { StartCoroutine(LoadUrl("http://192.168.2.141:8080/update.json", (result) => { Debug.Log(result.state + "," + result.www.error + "," + result.www.url); if (result.state == LoadStatus.OK) { Dictionary <string, object> dic = MiniJSON.Json.Deserialize(result.www.text) as Dictionary <string, object>; List <AssetItem> list = new List <AssetItem>(dic.Count); foreach (var VARIABLE in dic) { string path = VARIABLE.Key; ulong crc = ulong.Parse((string)VARIABLE.Value); string newPath = Application.persistentDataPath + "/" + path; if (!File.Exists(newPath)) { Debug.Log(newPath + ",no Exist"); list.Add(new AssetItem(path, crc)); } else { ulong tempCrc = Crc32Utils.GetCRC32Str(File.ReadAllBytes(newPath)); if (tempCrc != crc) { Debug.Log(newPath + ",crc is not same"); list.Add(new AssetItem(path, crc)); } } } if (list.Count > 0) { StartCoroutine(LoadUrl("http://192.168.2.141:8080/" + list[index].p, (loadResult) => { if (loadResult.state == LoadStatus.OK) { ulong tempCrc = Crc32Utils.GetCRC32Str(loadResult.www.bytes); if (tempCrc == list[index].c) { string newPath = Application.persistentDataPath + "/" + list[index].p; Debug.Log(newPath); File.WriteAllBytes(newPath, loadResult.www.bytes); } else { //TODO 要处理失败 } } //TODO 要处理失败 }, 0)); } } else { //TODO 要处理失败 } })); //Dictionary<string,string> dic=new Dictionary<string, string>(); //dic.Add("path1", "1"); //dic.Add("path2", "2"); //Debug.Log(MiniJSON.Json.Serialize(dic)); //byte[] bytes = File.ReadAllBytes(Application.dataPath + "/StreamingAssets/RawImage.u3d"); //Debug.Log(Crc32Utils.GetCRC32Str(bytes)); }