protected override void AfterDownload() { try { XmlPath = Files.First(f => regexXmlPath.IsMatch(f.Path)).Path; } catch (InvalidOperationException) { throw new InvalidOperationException("该 MOD 缺少 XML 配置文件,本资源属于无效资源,请联系上传者。"); } try { ExePath = Files.First(f => regexExePath.IsMatch(f.Path)).Path; } catch (InvalidOperationException) { throw new InvalidOperationException("该 MOD 缺少游戏主程序 EXE 文件,本资源属于无效资源,请联系上传者。"); } var root = XElement.Load(ProgramModel.MakeHawkempirePath(XmlPath)); FolderPath = @"Games\" + (root.Element("path")?.Value ?? throw new InvalidOperationException("该 MOD 的 XML 配置文件格式错误,本资源属于无效资源,请联系上传者。")); ProgramModel.Mods.Add(this); }
public void OpenFolder(ModOpenFolder which) { var folder = ProgramModel.MakeHawkempirePath(Path.Combine(FolderPath, Id == AGE2_1C ? modOpenFolders_AGE2_1C[(int)which] : modOpenFolders[(int)which])); Directory.CreateDirectory(folder); Process.Start(folder); }
public void Run() { CopyExe(); var exePath = ProgramModel.MakeHawkempirePath($@"age2_x1\{Path.GetFileName(ExePath)}"); Process.Start(new ProcessStartInfo(exePath, ProgramModel.Config.Splash ? string.Empty : "nostartup") { WorkingDirectory = Path.GetDirectoryName(exePath), UseShellExecute = true, }); }
private void CopyLanguageDll(int id, string dstPath, string dstName) { var fm = Files.FirstOrDefault(f => f.Id == id); if (fm != null) { try { File.Copy(fm.FullPathName, Path.Combine(ProgramModel.MakeHawkempirePath(dstPath), dstName), true); } catch (IOException) { } } }
public void Activate() { var tauntPath = ProgramModel.MakeHawkempirePath("taunt"); if (IsBuiltIn) { foreach (var file in Directory.GetFiles(ProgramModel.MakeExeRelativePath(Path))) { File.Copy(file, System.IO.Path.Combine(tauntPath, System.IO.Path.GetFileName(file)), true); } } else { foreach (var file in Files) { File.Copy(file.FullPathName, System.IO.Path.Combine(tauntPath, System.IO.Path.GetFileName(file.Path)), true); } } }
public static void ApplyDrses() { var dic = builtInDrsFiles.ToDictionary(f => f, f => DrsFile.Load(Path.Combine(ProgramModel.MakeExeRelativePath("drs"), f))); foreach (var drs in ProgramModel.ActiveDrses.Reverse()) { foreach (var file in drs.Files) { var extension = Path.GetExtension(file.Path).TrimStart('.').ToLowerInvariant(); var id = int.Parse(Path.GetFileNameWithoutExtension(file.Path)); var drsName = Path.GetFileName(Path.GetDirectoryName(file.Path)).ToLowerInvariant(); dic[drs.MapDrsName(drsName)].GetOrAdd((DrsTableClass)Array.IndexOf(drsTables, extension))[id] = File.ReadAllBytes(file.FullPathName); } } foreach (var pair in dic) { pair.Value.Save(ProgramModel.MakeHawkempirePath(GetDrsPath(pair.Key))); } }
public void CopyExe() { if (IsBuiltIn) { File.Copy(ProgramModel.MakeExeRelativePath(ExePath), ProgramModel.MakeHawkempirePath($@"age2_x1\{Path.GetFileName(ExePath)}"), true); } if (new[] { -1, -3, -4, -5, -6 }.Contains(Id)) { File.Copy(ProgramModel.MakeExeRelativePath(XmlPath), Path.Combine(ProgramModel.MakeHawkempirePath("games"), Path.GetFileName(XmlPath)), true); } if (Id == AGE2_WK && WK_VERSION > ProgramModel.Config.WkVersion) { foreach (var dir in Directory.GetDirectories(ProgramModel.MakeExeRelativePath(@"builtin\WololoKingdoms"), "*", SearchOption.AllDirectories)) { try { Directory.CreateDirectory(dir.Replace(ProgramModel.MakeExeRelativePath("builtin"), ProgramModel.MakeHawkempirePath("games"))); } catch (IOException) { } } foreach (var file in Directory.GetFiles(ProgramModel.MakeExeRelativePath(@"builtin\WololoKingdoms"), "*", SearchOption.AllDirectories)) { try { File.Copy(file, file.Replace(ProgramModel.MakeExeRelativePath("builtin"), ProgramModel.MakeHawkempirePath("games")), true); } catch (IOException) { } } try { Directory.CreateDirectory(ProgramModel.MakeHawkempirePath(@"games\WololoKingdoms\data")); } catch (IOException) { } try { File.Copy(ProgramModel.MakeExeRelativePath(@"dat\original\empires2_x1_p1_wk.dat"), ProgramModel.MakeHawkempirePath(@"games\WololoKingdoms\data\empires2_x1_p1.dat"), true); } catch (IOException) { } try { File.Copy(ProgramModel.MakeExeRelativePath(@"drs\gamedata_x1_wk.drs"), ProgramModel.MakeHawkempirePath(@"games\WololoKingdoms\data\gamedata_x1.drs"), true); } catch (IOException) { } try { File.Copy(ProgramModel.MakeExeRelativePath(@"drs\gamedata_x1_p1_wk.drs"), ProgramModel.MakeHawkempirePath(@"games\WololoKingdoms\data\gamedata_x1_p1.drs"), false); } catch (IOException) { // ignored } File.Copy(ProgramModel.MakeExeRelativePath(@"dll\zh\language_x1_p1_wk.dll"), ProgramModel.MakeHawkempirePath(@"games\WololoKingdoms\data\language_x1_p1.dll"), true); ProgramModel.Config.WkVersion = WK_VERSION; } if (Id == AGE2_WK && ProgramModel.Config.IsSteamHDInstalled == SteamHDInstallStatus.NotInstalled) { try { File.Copy(ProgramModel.MakeExeRelativePath(@"exe\age2_wk_nohd.exe"), ProgramModel.MakeHawkempirePath(@"age2_x1\age2_wk.exe"), true); } catch (IOException) { } } }