1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-18 06:15:49 +02:00

Add resource hotswap for easier debugging

This commit is contained in:
chylex 2018-04-04 23:13:44 +02:00
parent caea8d4315
commit a5379d290c
3 changed files with 77 additions and 4 deletions

View File

@ -297,6 +297,10 @@ public void ReinjectCustomCSS(string css){
} }
public void ReloadToTweetDeck(){ public void ReloadToTweetDeck(){
#if DEBUG
Resources.ScriptLoader.HotSwap();
#endif
browser.ReloadToTweetDeck(); browser.ReloadToTweetDeck();
AnalyticsFile.BrowserReloads.Trigger(); AnalyticsFile.BrowserReloads.Trigger();
} }

View File

@ -1,6 +1,7 @@
Param( Param(
[Parameter(Mandatory = $True, Position = 1)][string] $targetDir, [Parameter(Mandatory = $True, Position = 1)][string] $targetDir,
[Parameter(Mandatory = $True, Position = 2)][string] $projectDir [Parameter(Mandatory = $True, Position = 2)][string] $projectDir,
[Parameter(Position = 3)][string] $version = ""
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
@ -8,14 +9,19 @@ $ErrorActionPreference = "Stop"
try{ try{
Write-Host "------------------------------" Write-Host "------------------------------"
$version = (Get-Item (Join-Path $targetDir "TweetDuck.exe")).VersionInfo.FileVersion if ($version.Equals("")){
$version = (Get-Item (Join-Path $targetDir "TweetDuck.exe")).VersionInfo.FileVersion
}
Write-Host "TweetDuck version" $version Write-Host "TweetDuck version" $version
Write-Host "------------------------------" Write-Host "------------------------------"
# Cleanup # Cleanup
Remove-Item -Path (Join-Path $targetDir "locales\*.pak") -Exclude "en-US.pak" if (Test-Path (Join-Path $targetDir "locales")){
Remove-Item -Path (Join-Path $targetDir "locales\*.pak") -Exclude "en-US.pak"
}
# Copy resources # Copy resources

View File

@ -5,14 +5,77 @@
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Other; using TweetDuck.Core.Other;
#if DEBUG
using System.Diagnostics;
#endif
namespace TweetDuck.Resources{ namespace TweetDuck.Resources{
static class ScriptLoader{ static class ScriptLoader{
private const string UrlPrefix = "td:"; private const string UrlPrefix = "td:";
#if DEBUG
private static readonly string HotSwapProjectRoot = FixPathSlash(Path.GetFullPath(Path.Combine(Program.ProgramPath, "../../../")));
private static readonly string HotSwapTargetDir = FixPathSlash(Path.Combine(HotSwapProjectRoot, "bin", "tmp"));
private static readonly string HotSwapRebuildScript = Path.Combine(HotSwapProjectRoot, "Resources", "PostBuild.ps1");
// TODO figure out hotswap support for plugins and scripts/plugins.* files
static ScriptLoader(){
if (File.Exists(HotSwapRebuildScript)){
Debug.WriteLine("Activating resource hot swap");
ResetHotSwap();
Application.ApplicationExit += (sender, args) => ResetHotSwap();
}
}
public static void HotSwap(){
if (!File.Exists(HotSwapRebuildScript)){
Debug.WriteLine("Failed resource hot swap, missing rebuild script: "+HotSwapRebuildScript);
return;
}
ResetHotSwap();
Directory.CreateDirectory(HotSwapTargetDir);
using(Process process = Process.Start(new ProcessStartInfo{
FileName = "powershell",
Arguments = $"-ExecutionPolicy Unrestricted -File \"{HotSwapRebuildScript}\" \"{HotSwapTargetDir}\\\" \"{HotSwapProjectRoot}\\\" \"{Program.VersionTag}\"",
WindowStyle = ProcessWindowStyle.Hidden
})){
// ReSharper disable once PossibleNullReferenceException
if (!process.WaitForExit(8000)){
Debug.WriteLine("Failed resource hot swap, script did not finish in time");
}
else if (process.ExitCode != 0){
Debug.WriteLine("Failed resource hot swap, script exited with code "+process.ExitCode);
}
}
}
private static void ResetHotSwap(){
try{
Directory.Delete(HotSwapTargetDir, true);
}catch(DirectoryNotFoundException){}
}
private static string FixPathSlash(string path){
return path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)+'\\';
}
#endif
public static string LoadResource(string name, bool silent = false, Control sync = null){ public static string LoadResource(string name, bool silent = false, Control sync = null){
try{ try{
string contents = File.ReadAllText(Path.Combine(Program.ScriptPath, name), Encoding.UTF8); string path = Program.ScriptPath;
#if DEBUG
if (Directory.Exists(HotSwapTargetDir)){
path = Path.Combine(HotSwapTargetDir, "scripts");
Debug.WriteLine("Hot swap active, redirecting "+name);
}
#endif
string contents = File.ReadAllText(Path.Combine(path, name), Encoding.UTF8);
int separator; int separator;
// first line can be either: // first line can be either: