Don't load resources previously downloaded

This commit is contained in:
Sardelka
2022-07-11 10:08:21 +08:00
parent b37ce4d0c1
commit abed0f146f
9 changed files with 24 additions and 45 deletions

View File

@ -14,6 +14,10 @@ namespace RageCoop.Client
{ {
var fr = new Packets.FileTransferRequest(); var fr = new Packets.FileTransferRequest();
fr.Unpack(data); fr.Unpack(data);
if (fr.Name.EndsWith(".zip"))
{
_zips.Add(fr.Name);
}
return new Packets.FileTransferResponse() return new Packets.FileTransferResponse()
{ {
ID= fr.ID, ID= fr.ID,
@ -39,7 +43,7 @@ namespace RageCoop.Client
{ {
try try
{ {
Main.Resources.Load(ResourceFolder); Main.Resources.Load(ResourceFolder,_zips.ToArray());
return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.Loaded }; return new Packets.FileTransferResponse() { ID=0, Response=FileResponse.Loaded };
} }
catch(Exception ex) catch(Exception ex)
@ -57,6 +61,7 @@ namespace RageCoop.Client
} }
} }
private static readonly Dictionary<int, DownloadFile> InProgressDownloads = new Dictionary<int, DownloadFile>(); private static readonly Dictionary<int, DownloadFile> InProgressDownloads = new Dictionary<int, DownloadFile>();
private static readonly List<string> _zips = new List<string>();
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 {ResourceFolder}\\{name} , id:{id}"); Main.Logger.Debug($"Downloading file to {ResourceFolder}\\{name} , id:{id}");
@ -140,6 +145,10 @@ namespace RageCoop.Client
{ {
InProgressDownloads.Remove(id); InProgressDownloads.Remove(id);
f.Dispose(); f.Dispose();
if (f.FileName.EndsWith(".zip"))
{
_zips.Add(f.FileName);
}
Main.Logger.Info($"Download finished:{f.FileName}"); Main.Logger.Info($"Download finished:{f.FileName}");
} }
else else
@ -166,6 +175,7 @@ namespace RageCoop.Client
File.Delete(zip); File.Delete(zip);
} }
} }
_zips.Clear();
} }
} }

View File

@ -92,7 +92,10 @@ namespace RageCoop.Client
public static PlayerData GetPlayer(SyncedPed p) public static PlayerData GetPlayer(SyncedPed p)
{ {
var player = GetPlayer(p.ID); var player = GetPlayer(p.ID);
player.Character=p; if (player!=null)
{
player.Character=p;
}
return player; return player;
} }
public static void RemovePlayer(int id) public static void RemovePlayer(int id)

View File

@ -82,21 +82,13 @@ namespace RageCoop.Client.Scripting
/// <summary> /// <summary>
/// Load all resources from the server /// Load all resources from the server
/// </summary> /// </summary>
/// <param name="path">The path to the directory containing all resources to load.</param> public void Load(string path,string[] zips)
public void Load(string path)
{ {
Unload(); Unload();
foreach (var d in Directory.GetDirectories(path)) foreach (var zip in zips)
{ {
if(Path.GetFileName(d).ToLower() != "data") var zipPath=Path.Combine(path, zip);
{ Logger?.Info($"Loading resource: {Path.GetFileNameWithoutExtension(zip)}");
Directory.Delete(d, true);
}
}
Directory.CreateDirectory(path);
foreach (var zipPath in Directory.GetFiles(path,"*.zip",SearchOption.TopDirectoryOnly))
{
Logger?.Info($"Loading resource: {Path.GetFileNameWithoutExtension(zipPath)}");
LoadResource(new ZipFile(zipPath),Path.Combine(path,"data")); LoadResource(new ZipFile(zipPath),Path.Combine(path,"data"));
} }
StartAll(); StartAll();

View File

@ -71,7 +71,6 @@ namespace RageCoop.Client
/// ///
/// </summary> /// </summary>
internal protected bool _lastFrozen=false; internal protected bool _lastFrozen=false;
internal bool IsFrozen { get; set; } = false;
internal int ModelHash { get; set; } internal int ModelHash { get; set; }
internal Vector3 Position { get; set; } internal Vector3 Position { get; set; }
internal Vector3 Rotation { get; set; } internal Vector3 Rotation { get; set; }

View File

@ -332,11 +332,6 @@ namespace RageCoop.Client
private void DisplayOnFoot() private void DisplayOnFoot()
{ {
if (IsFrozen != _lastFrozen)
{
MainPed.SetFrozen(IsFrozen);
_lastFrozen=IsFrozen;
}
if (IsInParachuteFreeFall) if (IsInParachuteFreeFall)
{ {
MainPed.PositionNoOffset = Vector3.Lerp(MainPed.Position, Position + Velocity, 0.5f); MainPed.PositionNoOffset = Vector3.Lerp(MainPed.Position, Position + Velocity, 0.5f);

View File

@ -127,20 +127,10 @@ namespace RageCoop.Client
{ {
MainVehicle.CustomSteeringAngle((float)(Math.PI / 180) * SteeringAngle); MainVehicle.CustomSteeringAngle((float)(Math.PI / 180) * SteeringAngle);
} }
if (MainVehicle.ThrottlePower!=ThrottlePower) MainVehicle.ThrottlePower=ThrottlePower;
{ MainVehicle.BrakePower=BrakePower;
MainVehicle.ThrottlePower=ThrottlePower;
} if (MainVehicle.Position.DistanceTo(Position)<5)
if (MainVehicle.BrakePower!=BrakePower)
{
MainVehicle.BrakePower=BrakePower;
}
if (IsFrozen != _lastFrozen)
{
MainVehicle.SetFrozen(IsFrozen);
_lastFrozen=IsFrozen;
}
else if (MainVehicle.Position.DistanceTo(Position)<5)
{ {
MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position); MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position);
if (IsFlipped) if (IsFlipped)

View File

@ -1,5 +0,0 @@
- name: Articles
href: articles/
- name: Api Documentation
href: api/
homepage: api/index.md

View File

@ -1,5 +0,0 @@
- name: Articles
href: articles/
- name: Api Documentation
href: api/
homepage: api/index.md

View File

@ -304,7 +304,7 @@ namespace RageCoop.Server.Scripting
/// <summary> /// <summary>
/// Register an handler to the specifed event hash, one event can have multiple handlers. /// Register an handler to the specifed event hash, one event can have multiple handlers.
/// </summary> /// </summary>
/// <param name="hash">An unique identifier of the event, you can hash your event name with <see cref="Core.Scripting.CustomEvents.Hash(string)"/></param> /// <param name="hash">An unique identifier of the event, you can hash your event name with <see cref="CustomEvents.Hash(string)"/></param>
/// <param name="handler">An handler to be invoked when the event is received from the server.</param> /// <param name="handler">An handler to be invoked when the event is received from the server.</param>
public void RegisterCustomEventHandler(int hash,Action<CustomEventReceivedArgs> handler) public void RegisterCustomEventHandler(int hash,Action<CustomEventReceivedArgs> handler)
{ {