Unload fix and small tweaks
This commit is contained in:
@ -19,6 +19,7 @@ namespace RageCoop.Client
|
||||
public static Script Instance;
|
||||
public DevTool()
|
||||
{
|
||||
Util.StartUpCheck();
|
||||
Instance = this;
|
||||
Tick += OnTick;
|
||||
KeyDown += OnKeyDown;
|
||||
|
@ -50,6 +50,7 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
public Main()
|
||||
{
|
||||
Util.StartUpCheck();
|
||||
Console.Info($"Starting {typeof(Main).FullName}, domain: {AppDomain.CurrentDomain.Id} {AppDomain.CurrentDomain.FriendlyName}");
|
||||
try
|
||||
{
|
||||
@ -76,7 +77,7 @@ namespace RageCoop.Client
|
||||
Directory.CreateDirectory(Settings.DataDirectory);
|
||||
Logger = new Logger()
|
||||
{
|
||||
Writers = new List<StreamWriter> { CoreUtils.OpenWriter(LogPath)},
|
||||
Writers = new List<StreamWriter> { CoreUtils.OpenWriter(LogPath) },
|
||||
#if DEBUG
|
||||
LogLevel = 0,
|
||||
#else
|
||||
|
@ -60,7 +60,7 @@ namespace RageCoop.Client
|
||||
|
||||
private static void ReloadDomain(object sender, EventArgs e)
|
||||
{
|
||||
Loader.DomainContext.RequestUnload();
|
||||
Loader.LoaderContext.RequestUnload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ namespace RageCoop.Client.Menus
|
||||
try { File.Delete(Path.Combine("Scripts", "RageCoop.Client.Installer.exe")); } catch { }
|
||||
API.QueueAction(() =>
|
||||
{
|
||||
Util.Reload();
|
||||
Loader.LoaderContext.RequestUnload();
|
||||
IsUpdating = false;
|
||||
});
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ using System.Resources;
|
||||
|
||||
|
||||
// Version informationr(
|
||||
[assembly: AssemblyVersion("1.5.4.300")]
|
||||
[assembly: AssemblyFileVersion("1.5.4.300")]
|
||||
[assembly: AssemblyVersion("1.5.4.328")]
|
||||
[assembly: AssemblyFileVersion("1.5.4.328")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||
|
||||
|
@ -120,16 +120,22 @@ namespace RageCoop.Client.Scripting
|
||||
/// <summary>
|
||||
/// This is equivalent of <see cref="GTA.Script.Tick"/>.
|
||||
/// </summary>
|
||||
/// <remarks>Calling <see cref="GTA.Script.Yield"/> in the handler will interfer other scripts, subscribe to <see cref="GTA.Script.Tick"/> instead.</remarks>
|
||||
[Obsolete]
|
||||
public static event EmptyEvent OnTick;
|
||||
|
||||
/// <summary>
|
||||
/// This is equivalent of <see cref="Script.KeyDown"/>
|
||||
/// </summary>
|
||||
/// <remarks>Calling <see cref="GTA.Script.Yield"/> in the handler will interfer other scripts, subscribe to <see cref="GTA.Script.KeyDown"/> instead.</remarks>
|
||||
[Obsolete]
|
||||
public static KeyEventHandler OnKeyDown;
|
||||
|
||||
/// <summary>
|
||||
/// This is equivalent of <see cref="Script.KeyUp"/>
|
||||
/// </summary>
|
||||
/// <remarks>Calling <see cref="GTA.Script.Yield"/> in the handler will interfer other scripts, subscribe to <see cref="GTA.Script.KeyUp"/> instead.</remarks>
|
||||
[Obsolete]
|
||||
public static KeyEventHandler OnKeyUp;
|
||||
|
||||
#region INVOKE
|
||||
|
@ -77,7 +77,7 @@ namespace RageCoop.Client.Scripting
|
||||
|
||||
StopScripts();
|
||||
LoadedResources.Clear();
|
||||
Loader.DomainContext.RequestUnload();
|
||||
Loader.LoaderContext.RequestUnload();
|
||||
}
|
||||
|
||||
private void Unpack(string zipPath, string dataFolderRoot)
|
||||
@ -110,7 +110,18 @@ namespace RageCoop.Client.Scripting
|
||||
var assemblies = new Dictionary<ResourceFile, Assembly>();
|
||||
foreach (var file in Directory.GetFiles(scriptsDir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
if (Path.GetFileName(file).CanBeIgnored()) { try { File.Delete(file); } catch { } continue; }
|
||||
if (Path.GetFileName(file).CanBeIgnored())
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
API.Logger.Warning($"Failed to delete API assembly: {file}. This may or may cause some unexpected behaviours.\n{ex}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
var relativeName = file.Substring(scriptsDir.Length + 1).Replace('\\', '/');
|
||||
var rfile = new ResourceFile()
|
||||
{
|
||||
|
@ -14,12 +14,20 @@ using System.Windows.Forms;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using SHVDN;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
[assembly: InternalsVisibleTo("RageCoop.Client.Installer")]
|
||||
namespace RageCoop.Client
|
||||
{
|
||||
internal static class Util
|
||||
{
|
||||
public static void StartUpCheck()
|
||||
{
|
||||
if (AppDomain.CurrentDomain.GetData("RageCoop.Client.LoaderContext") == null)
|
||||
{
|
||||
throw new Exception($"Client not loaded with loader, please re-install using the installer to fix this issue");
|
||||
}
|
||||
}
|
||||
public static SizeF ResolutionMaintainRatio
|
||||
{
|
||||
get
|
||||
@ -207,62 +215,8 @@ namespace RageCoop.Client
|
||||
Function.Call(Hash.SET_RADIO_TO_STATION_INDEX, index);
|
||||
}
|
||||
|
||||
#region WIN32
|
||||
|
||||
private const UInt32 WM_KEYDOWN = 0x0100;
|
||||
public static void Reload()
|
||||
{
|
||||
string reloadKey = "None";
|
||||
var lines = File.ReadAllLines("ScriptHookVDotNet.ini");
|
||||
foreach (var l in lines)
|
||||
{
|
||||
var ss = l.Split('=');
|
||||
if (ss.Length > 0 && ss[0] == "ReloadKey")
|
||||
{
|
||||
reloadKey = ss[1];
|
||||
}
|
||||
}
|
||||
var lineList = lines.ToList();
|
||||
if (reloadKey == "None")
|
||||
{
|
||||
foreach (var l in lines)
|
||||
{
|
||||
var ss = l.Split('=');
|
||||
if (ss.Length > 0 && ss[0] == "ReloadKey")
|
||||
{
|
||||
reloadKey = ss[1];
|
||||
lineList.Remove(l);
|
||||
}
|
||||
}
|
||||
lineList.Add("ReloadKey=Insert");
|
||||
File.WriteAllLines("ScriptHookVDotNet.ini", lineList.ToArray());
|
||||
GTA.UI.Notification.Show("Reload cannot be performed automatically, please type \"Reload()\" manually in the SHVDN console.");
|
||||
}
|
||||
Keys key = (Keys)Enum.Parse(typeof(Keys), reloadKey, true);
|
||||
|
||||
// Move log file so it doesn't get deleted
|
||||
Main.Logger.Dispose();
|
||||
|
||||
var path = Main.LogPath + ".last.log";
|
||||
try
|
||||
{
|
||||
if (File.Exists(path)) { File.Delete(path); }
|
||||
if (File.Exists(Main.LogPath)) { File.Move(Main.LogPath, path); }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GTA.UI.Notification.Show(ex.Message);
|
||||
}
|
||||
|
||||
PostMessage(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle, WM_KEYDOWN, (int)key, 0);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
|
||||
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern ulong GetTickCount64();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
public WorldThread()
|
||||
{
|
||||
Util.StartUpCheck();
|
||||
Instance = this;
|
||||
Tick += OnTick;
|
||||
Aborted += (sender, e) =>
|
||||
|
Reference in New Issue
Block a user