Fix data folder

This commit is contained in:
Sardelka 2022-07-02 13:53:14 +08:00
parent c73ff96690
commit 335ea2ca38
5 changed files with 19 additions and 14 deletions

View File

@ -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,

View File

@ -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<int, DownloadFile> InProgressDownloads = new Dictionary<int, DownloadFile>();
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;

View File

@ -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))
{

View File

@ -64,8 +64,8 @@ namespace RageCoop.Client
/// </summary>
public int WorldPedSoftLimit { get; set; } = 50;
/// <summary>
/// The directory where resources downloaded from server will be placed.
/// The directory where log and resources downloaded from server will be placed.
/// </summary>
public string ResourceDirectory { get; set; } = "RageCoop\\Resources";
public string DataDirectory { get; set; } = "Scripts\\RageCoop\\Data";
}
}

View File

@ -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))