diff --git a/RageCoop.Client/Main.cs b/RageCoop.Client/Main.cs index 3531fe9..fc85030 100644 --- a/RageCoop.Client/Main.cs +++ b/RageCoop.Client/Main.cs @@ -45,9 +45,10 @@ namespace RageCoop.Client public Main() { Settings = Util.ReadSettings(); + Directory.CreateDirectory(Settings.DataDirectory); Logger=new Logger() { - LogPath=$"RageCoop\\RageCoop.Client.log", + LogPath=$"{Settings.DataDirectory}\\RageCoop.Client.log", UseConsole=false, #if DEBUG LogLevel = 0, diff --git a/RageCoop.Client/Networking/DownloadManager.cs b/RageCoop.Client/Networking/DownloadManager.cs index b4b7ecb..527716f 100644 --- a/RageCoop.Client/Networking/DownloadManager.cs +++ b/RageCoop.Client/Networking/DownloadManager.cs @@ -40,7 +40,7 @@ namespace RageCoop.Client { try { - Main.Resources.Load(downloadFolder); + Main.Resources.Load(DownloadFolder); return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.Loaded }; } catch(Exception ex) @@ -52,18 +52,21 @@ namespace RageCoop.Client } }); } - static string downloadFolder = Path.Combine(Main.Settings.ResourceDirectory, Main.Settings.LastServerAddress.Replace(":", ".")); - + public static string DownloadFolder { + get { + return Path.Combine(Main.Settings.DataDirectory,"Resources", Main.Settings.LastServerAddress.Replace(":", ".")); + } + } private static readonly Dictionary InProgressDownloads = new Dictionary(); public static bool AddFile(int id, string name, long length) { - Main.Logger.Debug($"Downloading file to {downloadFolder}\\{name} , id:{id}"); - if (!Directory.Exists(downloadFolder)) + Main.Logger.Debug($"Downloading file to {DownloadFolder}\\{name} , id:{id}"); + if (!Directory.Exists(DownloadFolder)) { - Directory.CreateDirectory(downloadFolder); + Directory.CreateDirectory(DownloadFolder); } - if (FileAlreadyExists(downloadFolder, name, length)) + if (FileAlreadyExists(DownloadFolder, name, length)) { Main.Logger.Debug($"File already exists! canceling download:{name}"); return false; @@ -81,7 +84,7 @@ namespace RageCoop.Client FileID = id, FileName = name, FileLength = length, - Stream = new FileStream($"{downloadFolder}\\{name}", FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite) + Stream = new FileStream($"{DownloadFolder}\\{name}", FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite) }); } return true; diff --git a/RageCoop.Client/Networking/MapLoader.cs b/RageCoop.Client/Networking/MapLoader.cs index 0102791..d2d4507 100644 --- a/RageCoop.Client/Networking/MapLoader.cs +++ b/RageCoop.Client/Networking/MapLoader.cs @@ -59,7 +59,7 @@ namespace RageCoop.Client public static void LoadAll() { - string downloadFolder = $"RageCoop\\Resources\\{Main.Settings.LastServerAddress.Replace(":", ".")}"; + string downloadFolder = DownloadManager.DownloadFolder; if (!Directory.Exists(downloadFolder)) { diff --git a/RageCoop.Client/Settings.cs b/RageCoop.Client/Settings.cs index 641a5c1..a97691e 100644 --- a/RageCoop.Client/Settings.cs +++ b/RageCoop.Client/Settings.cs @@ -64,8 +64,8 @@ namespace RageCoop.Client /// public int WorldPedSoftLimit { get; set; } = 50; /// - /// The directory where resources downloaded from server will be placed. + /// The directory where log and resources downloaded from server will be placed. /// - public string ResourceDirectory { get; set; } = "RageCoop\\Resources"; + public string DataDirectory { get; set; } = "Scripts\\RageCoop\\Data"; } } diff --git a/RageCoop.Client/Util/Util.cs b/RageCoop.Client/Util/Util.cs index c3c1e90..1777a1c 100644 --- a/RageCoop.Client/Util/Util.cs +++ b/RageCoop.Client/Util/Util.cs @@ -89,11 +89,12 @@ namespace RageCoop.Client #endregion + public static string SettingsPath= "Scripts\\RageCoop\\Data\\RageCoop.Client.Settings.xml"; public static Settings ReadSettings() { XmlSerializer ser = new XmlSerializer(typeof(Settings)); - string path = $"RageCoop\\RageCoop.Client.Settings.xml"; + string path = SettingsPath; Directory.CreateDirectory(Directory.GetParent(path).FullName); Settings settings = null; @@ -123,7 +124,7 @@ namespace RageCoop.Client { try { - string path = $"RageCoop\\RageCoop.Client.Settings.xml"; + string path = SettingsPath ; Directory.CreateDirectory(Directory.GetParent(path).FullName); using (FileStream stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))