Dynamically resolve data path
This commit is contained in:
@ -42,12 +42,14 @@ namespace RageCoop.Client
|
|||||||
private static bool _lastDead;
|
private static bool _lastDead;
|
||||||
public static bool CefRunning;
|
public static bool CefRunning;
|
||||||
public static bool IsUnloading { get; private set; }
|
public static bool IsUnloading { get; private set; }
|
||||||
|
public static Script Instance { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't use it!
|
/// Don't use it!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
Directory.CreateDirectory(DataPath);
|
Directory.CreateDirectory(DataPath);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -72,7 +74,7 @@ namespace RageCoop.Client
|
|||||||
};
|
};
|
||||||
Log.OnFlush += (line, formatted) =>
|
Log.OnFlush += (line, formatted) =>
|
||||||
{
|
{
|
||||||
SHVDN.Logger.Write(line.Message, (uint)line.LogLevel);
|
SHVDN.Logger.Write($"[RageCoop] {line.Message}", (uint)line.LogLevel);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run static constructor to register all function pointers and remoting entries
|
// Run static constructor to register all function pointers and remoting entries
|
||||||
|
@ -7,12 +7,34 @@ global using static RageCoop.Client.Main;
|
|||||||
global using Console = GTA.Console;
|
global using Console = GTA.Console;
|
||||||
global using static RageCoop.Core.Shared;
|
global using static RageCoop.Core.Shared;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System;
|
||||||
|
using SHVDN;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace RageCoop.Client
|
namespace RageCoop.Client
|
||||||
{
|
{
|
||||||
internal static class Shared
|
internal static class Shared
|
||||||
{
|
{
|
||||||
public static string BasePath = "RageCoop";
|
private static string GetBasePath()
|
||||||
|
{
|
||||||
|
FileInfo info;
|
||||||
|
string realScriptDir = Directory.GetParent(Instance.FilePath).FullName;
|
||||||
|
nextTarget:
|
||||||
|
info = new(realScriptDir);
|
||||||
|
if (info.LinkTarget != null)
|
||||||
|
{
|
||||||
|
realScriptDir = info.LinkTarget;
|
||||||
|
goto nextTarget;
|
||||||
|
}
|
||||||
|
if (Path.GetFileName(realScriptDir).ToLower() != "scripts")
|
||||||
|
throw new FileNotFoundException($"Unexpected link target {realScriptDir}");
|
||||||
|
|
||||||
|
var baseDir = Directory.GetParent(realScriptDir).FullName;
|
||||||
|
Logger.Debug($"Base directory is {baseDir}");
|
||||||
|
return baseDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string BasePath = GetBasePath();
|
||||||
public static string DataPath = Path.Combine(BasePath, "Data");
|
public static string DataPath = Path.Combine(BasePath, "Data");
|
||||||
public static string LogPath = Path.Combine(DataPath, "RageCoop.Client.log");
|
public static string LogPath = Path.Combine(DataPath, "RageCoop.Client.log");
|
||||||
public static string SettingsPath = Path.Combine(DataPath, "Setting.json");
|
public static string SettingsPath = Path.Combine(DataPath, "Setting.json");
|
||||||
|
Reference in New Issue
Block a user