Skip to content

Commit

Permalink
Force TLS 1.2 and improve logging
Browse files Browse the repository at this point in the history
Forcing TLS 1.2 seems to be needed on some computers.

All logging now goes through thcrap log_print, so the application logs
will also be included in thcrap_log.txt.
  • Loading branch information
brliron committed Apr 16, 2021
1 parent cc05aa2 commit 1d23ca2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
12 changes: 11 additions & 1 deletion GamesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@ private static async Task<Game> GameDomToObject(WebClient webClient, HtmlNode ga

public static async Task<List<Game>> Reload()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
WebClient webClient = new WebClient();
string mainPage = await webClient.DownloadStringTaskAsync(GamesList.BaseURL);
string mainPage;
try
{
mainPage = await webClient.DownloadStringTaskAsync(GamesList.BaseURL);
}
catch (Exception e)
{
ThcrapDll.log_print("Could not download games list: " + e.Message + "\n");
return null;
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(mainPage);

Expand Down
6 changes: 1 addition & 5 deletions Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Logger(Dispatcher dispatcher, TextBox container)
ThcrapDll.log_init(0);
}

public void Log(string msg)
private void Log(string msg)
{
Console.Write(msg);
if (dispatcher.Thread == Thread.CurrentThread)
Expand All @@ -49,9 +49,5 @@ public void Log(string msg)
});
}
}
public void LogLine(string msg)
{
this.Log(msg + "\n");
}
}
}
37 changes: 26 additions & 11 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,33 @@ private void Window_Loaded(object sender, RoutedEventArgs e)

Task.Run(() =>
{
this.repoList = Repo.Discovery("https://srv.thpatch.net/");
var repoList = Repo.Discovery("https://srv.thpatch.net/");
if (repoList == null)
return;
this.repoList = repoList;
this.Dispatcher.Invoke(() => this.uiRepos.ItemsSource = repoList);
logger.LogLine("Repo discovery finished");
ThcrapDll.log_print("Repo discovery finished\n");
});
}

private async void ReloadGamesList(object sender, RoutedEventArgs e)
{
logger.LogLine("Reloading games list from " + GamesList.BaseURL + " ...");
gamesList = await GamesList.Reload();
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;
logger.LogLine("Games list reloaded and saved to disk!");
ThcrapDll.log_print("Games list reloaded and saved to disk!\n");
}

private string GeneratePatchNameFromStack()
Expand Down Expand Up @@ -128,7 +143,7 @@ private void CreateExe(string game_id, string icon_path)

private async Task CreateStandalonePatchForGame(Game game)
{
logger.LogLine("Generating standalone for " + game.Name + "...");
ThcrapDll.log_print("Generating standalone for " + game.Name + "...\n");
Directory.CreateDirectory(game.Id);
Directory.CreateDirectory(game.Id + "\\thcrap\\");
Environment.CurrentDirectory = game.Id + "\\thcrap\\";
Expand All @@ -151,17 +166,17 @@ await Task.Run(() => ThcrapUpdateDll.stack_update(
case ThcrapUpdateDll.get_status_t.GET_OK:
var patch = Marshal.PtrToStructure<ThcrapDll.patch_t>(status.patch);
string patch_id = Marshal.PtrToStringAnsi(patch.id);
logger.LogLine(string.Format("[{0}/{1}] {2}/{3}: OK ({4}b)",
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:
logger.LogLine(status.url + " : " + status.error);
ThcrapDll.log_print(status.url + " : " + status.error + "\n");
break;
case ThcrapUpdateDll.get_status_t.GET_CRC32_ERROR:
logger.LogLine(status.url + " : CRC32 error");
ThcrapDll.log_print(status.url + " : CRC32 error\n");
break;
}
return true;
Expand All @@ -188,7 +203,7 @@ await Task.Run(() => ThcrapUpdateDll.stack_update(

ThcrapDll.stack_free();
Environment.CurrentDirectory = "..";
logger.LogLine("Standalone for " + game.Name + " generated!");
ThcrapDll.log_print("Standalone for " + game.Name + " generated!\n");
}
private async void GenerateStandalonePatch(object sender, RoutedEventArgs e)
{
Expand All @@ -197,7 +212,7 @@ private async void GenerateStandalonePatch(object sender, RoutedEventArgs e)
Directory.CreateDirectory("out");
Environment.CurrentDirectory = "out";

logger.LogLine("Downloading thcrap...");
ThcrapDll.log_print("Downloading thcrap...\n");
var webClient = new WebClient();
await webClient.DownloadFileTaskAsync("https://thcrap.thpatch.net/stable/thcrap.zip", "thcrap.zip");

Expand Down
3 changes: 0 additions & 3 deletions StandaloneGeneratorV3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="res\Icon_th18.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="res\thcrap\bin\jansson.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
2 changes: 2 additions & 0 deletions ThcrapDll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public delegate void log_nprint_cb(
public static extern void log_init(int console);
[DllImport("res\\thcrap\\bin\\thcrap.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void log_set_hook(log_print_cb hookproc, log_nprint_cb hookproc2);
[DllImport("res\\thcrap\\bin\\thcrap.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void log_print(string log);

// repo
[DllImport("res\\thcrap\\bin\\thcrap.dll", CallingConvention = CallingConvention.Cdecl)]
Expand Down

0 comments on commit 1d23ca2

Please sign in to comment.