mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-22 00:15:48 +02:00
Move resource hot swap code to core library
This commit is contained in:
parent
3aace0b399
commit
7c8b43adfe
@ -1,55 +1,49 @@
|
||||
#if DEBUG
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using TweetLib.Core;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TweetDuck;
|
||||
|
||||
namespace TweetDuck.Resources {
|
||||
static class ResourceHotSwap {
|
||||
private static readonly string HotSwapProjectRoot = FixPathSlash(Path.GetFullPath(Path.Combine(App.ProgramPath, "../../../")));
|
||||
private static readonly string HotSwapTargetDir = FixPathSlash(Path.Combine(HotSwapProjectRoot, "bin", "tmp"));
|
||||
private static readonly string HotSwapRebuildScript = Path.Combine(HotSwapProjectRoot, "Resources", "PostBuild.ps1");
|
||||
namespace TweetLib.Core.Resources {
|
||||
public static class ResourceHotSwap {
|
||||
private static readonly string HotSwapProjectRoot = FixPathSlash(Path.GetFullPath(Path.Combine(App.ProgramPath, "../../../../../")));
|
||||
private static readonly string HotSwapTargetDir = FixPathSlash(Path.GetFullPath(Path.Combine(App.ProgramPath, "../../../bin/tmp")));
|
||||
|
||||
private static string FixPathSlash(string path) {
|
||||
return path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + '\\';
|
||||
}
|
||||
|
||||
public static void Run() {
|
||||
if (!File.Exists(HotSwapRebuildScript)) {
|
||||
Debug.WriteLine($"Failed resource hot swap, missing rebuild script: {HotSwapRebuildScript}");
|
||||
Debug.WriteLine("Performing resource hot swap...");
|
||||
|
||||
string resourcesRoot = Path.Combine(HotSwapProjectRoot, "resources");
|
||||
if (!Directory.Exists(resourcesRoot)) {
|
||||
Debug.WriteLine("Failed resource hot swap, cannot find resources folder: " + resourcesRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.WriteLine("Performing resource hot swap...");
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
DeleteHotSwapFolder();
|
||||
Directory.CreateDirectory(HotSwapTargetDir);
|
||||
Directory.CreateDirectory(Path.Combine(HotSwapTargetDir, "plugins"));
|
||||
Directory.CreateDirectory(Path.Combine(HotSwapTargetDir, "plugins", "user"));
|
||||
CopyDirectory(Path.Combine(HotSwapProjectRoot, "Resources", "Content"), Path.Combine(HotSwapTargetDir, "resources"));
|
||||
CopyDirectory(Path.Combine(HotSwapProjectRoot, "Resources", "Guide"), Path.Combine(HotSwapTargetDir, "guide"));
|
||||
CopyDirectory(Path.Combine(HotSwapProjectRoot, "Resources", "Plugins"), Path.Combine(HotSwapTargetDir, "plugins", "official"));
|
||||
CopyDirectory(Path.Combine(resourcesRoot, "Content"), Path.Combine(HotSwapTargetDir, "resources"));
|
||||
CopyDirectory(Path.Combine(resourcesRoot, "Guide"), Path.Combine(HotSwapTargetDir, "guide"));
|
||||
CopyDirectory(Path.Combine(resourcesRoot, "Plugins"), Path.Combine(HotSwapTargetDir, "plugins", "official"));
|
||||
Directory.Move(Path.Combine(HotSwapTargetDir, "plugins", "official", ".debug"), Path.Combine(HotSwapTargetDir, "plugins", "user", ".debug"));
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
using (Process process = Process.Start(new ProcessStartInfo {
|
||||
FileName = "powershell",
|
||||
Arguments = $"-NoProfile -ExecutionPolicy Unrestricted -File \"{HotSwapRebuildScript}\" \"{HotSwapTargetDir}\\\" \"{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");
|
||||
return;
|
||||
}
|
||||
else if (process.ExitCode != 0) {
|
||||
Debug.WriteLine($"Failed resource hot swap, script exited with code {process.ExitCode}");
|
||||
return;
|
||||
}
|
||||
foreach (var file in Directory.EnumerateFiles(Path.Combine(HotSwapTargetDir, "plugins"), "*.meta", SearchOption.AllDirectories)) {
|
||||
var lines = File.ReadLines(file, Encoding.UTF8)
|
||||
.Select(static line => line.Replace("{version}", Version.Tag))
|
||||
.ToArray();
|
||||
|
||||
File.WriteAllLines(file, lines, Encoding.UTF8);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"Finished rebuild script in {sw.ElapsedMilliseconds} ms");
|
||||
Debug.WriteLine($"Finished resource hot swap in {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
Directory.Delete(App.ResourcesPath, true);
|
||||
Directory.Delete(App.GuidePath, true);
|
@ -345,7 +345,7 @@ public void ResumeNotification() {
|
||||
|
||||
public void ReloadToTweetDeck() {
|
||||
#if DEBUG
|
||||
Resources.ResourceHotSwap.Run();
|
||||
ResourceHotSwap.Run();
|
||||
resourceCache.ClearCache();
|
||||
#else
|
||||
if (ModifierKeys.HasFlag(Keys.Shift)) {
|
||||
|
@ -143,7 +143,6 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Reporter.cs" />
|
||||
<Compile Include="Resources\ResourceHotSwap.cs" />
|
||||
<Compile Include="Updates\UpdateCheckClient.cs" />
|
||||
<Compile Include="Updates\UpdateInstaller.cs" />
|
||||
<Compile Include="Utils\BrowserUtils.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user