75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CarManagerV3.Manager;
|
|
|
|
namespace CarManagerV3.Classes
|
|
{
|
|
internal class FileMeta
|
|
{
|
|
private string version;
|
|
private DateTime lastModified;
|
|
|
|
public string Version { get { return version; } set { version = value; } }
|
|
public DateTime LastModified { get { return lastModified; } }
|
|
|
|
public FileMeta(string version)
|
|
{
|
|
this.version = version;
|
|
this.lastModified = DateTime.Now;
|
|
}
|
|
|
|
public static FileMeta FromCSV(string csv)
|
|
{
|
|
string[] parts = csv.Split(';');
|
|
if (parts.Length < 3)
|
|
{
|
|
throw new FormatException("CSV format is incorrect. Expected format: product;version;lastModified");
|
|
}
|
|
return new FileMeta(parts[1]) { lastModified = DateTime.Parse(parts[2]) };
|
|
}
|
|
|
|
public static FileMeta Generate()
|
|
{
|
|
string version = Updater.GetCurrentVersion();
|
|
return new FileMeta(version);
|
|
}
|
|
|
|
public static bool IsFileMeta(string csv)
|
|
{
|
|
return csv.StartsWith("CarManager3;");
|
|
}
|
|
|
|
public static bool IsOlderVersion(FileMeta meta)
|
|
{
|
|
string version = Updater.GetCurrentVersion();
|
|
return Updater.IsNewerVersion(version, meta.Version);
|
|
}
|
|
|
|
public static bool NeedsUpdate(FileMeta meta)
|
|
{
|
|
string version = Updater.GetCurrentVersion();
|
|
return Updater.IsNewerVersion(version, meta.Version) && FileUpdate.GetRequiredUpdates(meta.Version).Count > 0;
|
|
}
|
|
|
|
public void Modify()
|
|
{
|
|
lastModified = DateTime.Now;
|
|
}
|
|
|
|
public string ToCSV()
|
|
{
|
|
return $"CarManager3;{version};{lastModified}";
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"File Version: {version}, Last Modified: {lastModified}";
|
|
}
|
|
|
|
|
|
}
|
|
}
|