private async void ReloadGamesList(object sender, RoutedEventArgs e) { ThcrapDll.log_print("Reloading games list from " + GamesList.BaseURL + " ...\n"); List <Game> gamesList = null; try { gamesList = await GamesList.Reload(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); throw; } if (gamesList == null) { return; } this.gamesList = gamesList; this.uiGamesList.ItemsSource = gamesList; ThcrapDll.log_print("Games list reloaded and saved to disk!\n"); }
public static List <Repo> Discovery(string start_url) { IntPtr repo_list = ThcrapUpdateDll.RepoDiscover(start_url); if (repo_list == IntPtr.Zero) { return(new List <Repo>()); } var out_list = new List <Repo>(); int current_repo = 0; IntPtr repo_ptr = Marshal.ReadIntPtr(repo_list, current_repo * IntPtr.Size); while (repo_ptr != IntPtr.Zero) { out_list.Add(new Repo(repo_ptr)); current_repo++; repo_ptr = Marshal.ReadIntPtr(repo_list, current_repo * IntPtr.Size); } ThcrapDll.thcrap_free(repo_list); return(out_list); }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Initialize logging this.logger = new Logger(this.Dispatcher, this.uiLogWindow); gamesList = GamesList.Load(); this.uiGamesList.ItemsSource = gamesList; selectedPatchesList = new ObservableCollection <RepoPatch>(); uiSelectedPatches.ItemsSource = selectedPatchesList; Task.Run(() => { var repoList = Repo.Discovery("https://srv.thpatch.net/"); if (repoList == null) { return; } this.repoList = repoList; this.Dispatcher.Invoke(() => this.uiRepos.ItemsSource = repoList); ThcrapDll.log_print("Repo discovery finished\n"); }); }
private async void GenerateStandalonePatch(object sender, RoutedEventArgs e) { if (Directory.Exists("out")) { Directory.Delete("out", true); } Directory.CreateDirectory("out"); Environment.CurrentDirectory = "out"; ThcrapDll.log_print("Downloading thcrap...\n"); var webClient = new WebClient(); await webClient.DownloadFileTaskAsync("https://thcrap.thpatch.net/stable/thcrap.zip", "thcrap.zip"); foreach (Game game in gamesList) { if (game.IsSelected) { await CreateStandalonePatchForGame(game); } } File.Delete("thcrap.zip"); Environment.CurrentDirectory = ".."; }
private async Task CreateStandalonePatchForGame(Game game) { ThcrapDll.log_print("Generating standalone for " + game.Name + "...\n"); Directory.CreateDirectory(game.Id); Directory.CreateDirectory(game.Id + "\\thcrap\\"); Environment.CurrentDirectory = game.Id + "\\thcrap\\"; ZipFile.ExtractToDirectory(@"..\..\thcrap.zip", "."); foreach (RepoPatch patch in selectedPatchesList) { await Task.Run(() => patch.AddToStack()); } await Task.Run(() => ThcrapUpdateDll.stack_update( (string fn, IntPtr filter_data) => (fn.Contains('/') == false) || fn.StartsWith(game.Id + "/") ? 1 : 0, IntPtr.Zero, (IntPtr status_, IntPtr param) => { var status = Marshal.PtrToStructure <ThcrapUpdateDll.progress_callback_status_t>(status_); switch (status.status) { case ThcrapUpdateDll.get_status_t.GET_DOWNLOADING: case ThcrapUpdateDll.get_status_t.GET_CANCELLED: break; case ThcrapUpdateDll.get_status_t.GET_OK: var patch = Marshal.PtrToStructure <ThcrapDll.patch_t>(status.patch); string patch_id = Marshal.PtrToStringAnsi(patch.id); ThcrapDll.log_print(string.Format("[{0}/{1}] {2}/{3}: OK ({4}b)\n", status.nb_files_downloaded, status.nb_files_total, patch_id, status.fn, status.file_size)); break; case ThcrapUpdateDll.get_status_t.GET_CLIENT_ERROR: case ThcrapUpdateDll.get_status_t.GET_SERVER_ERROR: case ThcrapUpdateDll.get_status_t.GET_SYSTEM_ERROR: ThcrapDll.log_print(status.url + " : " + status.error + "\n"); break; case ThcrapUpdateDll.get_status_t.GET_CRC32_ERROR: ThcrapDll.log_print(status.url + " : CRC32 error\n"); break; } return(true); }, IntPtr.Zero) ); var runconfig = new Runconfig(); foreach (RepoPatch patch in selectedPatchesList) { runconfig.patches.Add(new RunconfigPatch(patch.Archive)); } runconfig.Save(uiConfigName.Text); var gamesJs = new Dictionary <string, string>() { { game.Id, "../" + game.Id + ".exe" }, { game.Id + "_custom", "../custom.exe" }, }; string jsonGamesJs = JsonSerializer.Serialize(gamesJs, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText("config/games.js", jsonGamesJs); Environment.CurrentDirectory = ".."; CreateExe(game.Id, game.ImagePath); CreateExe(game.Id + "_custom", null); ThcrapDll.stack_free(); Environment.CurrentDirectory = ".."; ThcrapDll.log_print("Standalone for " + game.Name + " generated!\n"); }