Fix data folder
This commit is contained in:
parent
c73ff96690
commit
335ea2ca38
@ -45,9 +45,10 @@ namespace RageCoop.Client
|
|||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
Settings = Util.ReadSettings();
|
Settings = Util.ReadSettings();
|
||||||
|
Directory.CreateDirectory(Settings.DataDirectory);
|
||||||
Logger=new Logger()
|
Logger=new Logger()
|
||||||
{
|
{
|
||||||
LogPath=$"RageCoop\\RageCoop.Client.log",
|
LogPath=$"{Settings.DataDirectory}\\RageCoop.Client.log",
|
||||||
UseConsole=false,
|
UseConsole=false,
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
LogLevel = 0,
|
LogLevel = 0,
|
||||||
|
@ -40,7 +40,7 @@ namespace RageCoop.Client
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Main.Resources.Load(downloadFolder);
|
Main.Resources.Load(DownloadFolder);
|
||||||
return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.Loaded };
|
return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.Loaded };
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
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>();
|
private static readonly Dictionary<int, DownloadFile> InProgressDownloads = new Dictionary<int, DownloadFile>();
|
||||||
public static bool AddFile(int id, string name, long length)
|
public static bool AddFile(int id, string name, long length)
|
||||||
{
|
{
|
||||||
Main.Logger.Debug($"Downloading file to {downloadFolder}\\{name} , id:{id}");
|
Main.Logger.Debug($"Downloading file to {DownloadFolder}\\{name} , id:{id}");
|
||||||
if (!Directory.Exists(downloadFolder))
|
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}");
|
Main.Logger.Debug($"File already exists! canceling download:{name}");
|
||||||
return false;
|
return false;
|
||||||
@ -81,7 +84,7 @@ namespace RageCoop.Client
|
|||||||
FileID = id,
|
FileID = id,
|
||||||
FileName = name,
|
FileName = name,
|
||||||
FileLength = length,
|
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;
|
return true;
|
||||||
|
@ -59,7 +59,7 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
public static void LoadAll()
|
public static void LoadAll()
|
||||||
{
|
{
|
||||||
string downloadFolder = $"RageCoop\\Resources\\{Main.Settings.LastServerAddress.Replace(":", ".")}";
|
string downloadFolder = DownloadManager.DownloadFolder;
|
||||||
|
|
||||||
if (!Directory.Exists(downloadFolder))
|
if (!Directory.Exists(downloadFolder))
|
||||||
{
|
{
|
||||||
|
@ -64,8 +64,8 @@ namespace RageCoop.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int WorldPedSoftLimit { get; set; } = 50;
|
public int WorldPedSoftLimit { get; set; } = 50;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The directory where resources downloaded from server will be placed.
|
/// The directory where log and resources downloaded from server will be placed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ResourceDirectory { get; set; } = "RageCoop\\Resources";
|
public string DataDirectory { get; set; } = "Scripts\\RageCoop\\Data";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,12 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
public static string SettingsPath= "Scripts\\RageCoop\\Data\\RageCoop.Client.Settings.xml";
|
||||||
public static Settings ReadSettings()
|
public static Settings ReadSettings()
|
||||||
{
|
{
|
||||||
XmlSerializer ser = new XmlSerializer(typeof(Settings));
|
XmlSerializer ser = new XmlSerializer(typeof(Settings));
|
||||||
|
|
||||||
string path = $"RageCoop\\RageCoop.Client.Settings.xml";
|
string path = SettingsPath;
|
||||||
Directory.CreateDirectory(Directory.GetParent(path).FullName);
|
Directory.CreateDirectory(Directory.GetParent(path).FullName);
|
||||||
Settings settings = null;
|
Settings settings = null;
|
||||||
|
|
||||||
@ -123,7 +124,7 @@ namespace RageCoop.Client
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string path = $"RageCoop\\RageCoop.Client.Settings.xml";
|
string path = SettingsPath ;
|
||||||
Directory.CreateDirectory(Directory.GetParent(path).FullName);
|
Directory.CreateDirectory(Directory.GetParent(path).FullName);
|
||||||
|
|
||||||
using (FileStream stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))
|
using (FileStream stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user