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

View File

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

View File

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

View File

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

View File

@ -332,11 +332,6 @@ namespace RageCoop.Client
private void DisplayOnFoot()
{
if (IsFrozen != _lastFrozen)
{
MainPed.SetFrozen(IsFrozen);
_lastFrozen=IsFrozen;
}
if (IsInParachuteFreeFall)
{
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);
}
if (MainVehicle.ThrottlePower!=ThrottlePower)
{
MainVehicle.ThrottlePower=ThrottlePower;
}
if (MainVehicle.BrakePower!=BrakePower)
{
MainVehicle.BrakePower=BrakePower;
}
if (IsFrozen != _lastFrozen)
{
MainVehicle.SetFrozen(IsFrozen);
_lastFrozen=IsFrozen;
}
else if (MainVehicle.Position.DistanceTo(Position)<5)
MainVehicle.ThrottlePower=ThrottlePower;
MainVehicle.BrakePower=BrakePower;
if (MainVehicle.Position.DistanceTo(Position)<5)
{
MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position);
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>
/// Register an handler to the specifed event hash, one event can have multiple handlers.
/// </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>
public void RegisterCustomEventHandler(int hash,Action<CustomEventReceivedArgs> handler)
{