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