Record save file paths in manifest. Support regex pathing in upload
parent
eb73885991
commit
7c22aaa139
|
@ -13,6 +13,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
|
@ -163,31 +164,42 @@ namespace LANCommander.SDK
|
|||
#region Add files from defined paths
|
||||
foreach (var savePath in manifest.SavePaths.Where(sp => sp.Type == "File"))
|
||||
{
|
||||
var localPath = Environment.ExpandEnvironmentVariables(savePath.Path.Replace('/', '\\').Replace("{InstallDir}", installDirectory));
|
||||
IEnumerable<string> localPaths;
|
||||
|
||||
if (Directory.Exists(localPath))
|
||||
if (savePath.IsRegex)
|
||||
{
|
||||
AddDirectoryToZip(archive, localPath, localPath, savePath.Id);
|
||||
}
|
||||
else if (File.Exists(localPath))
|
||||
{
|
||||
archive.AddEntry(Path.Combine(savePath.Id.ToString(), savePath.Path.Replace("{InstallDir}/", "")), localPath);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
var regex = new Regex(Environment.ExpandEnvironmentVariables(savePath.Path.Replace('/', '\\').Replace("{InstallDir}", installDirectory)));
|
||||
|
||||
#region Add files from defined paths
|
||||
foreach (var savePath in manifest.SavePaths.Where(sp => sp.Type == "File"))
|
||||
{
|
||||
var localPath = Environment.ExpandEnvironmentVariables(savePath.Path.Replace('/', '\\').Replace("{InstallDir}", installDirectory));
|
||||
|
||||
if (Directory.Exists(localPath))
|
||||
{
|
||||
AddDirectoryToZip(archive, localPath, localPath, savePath.Id);
|
||||
localPaths = Directory.GetFiles(installDirectory, "*", SearchOption.AllDirectories)
|
||||
.Where(p => regex.IsMatch(p))
|
||||
.ToList();
|
||||
}
|
||||
else if (File.Exists(localPath))
|
||||
else
|
||||
localPaths = new string[] { savePath.Path };
|
||||
|
||||
var entries = new List<SavePathEntry>();
|
||||
|
||||
foreach (var localPath in localPaths)
|
||||
{
|
||||
archive.AddEntry(Path.Combine(savePath.Id.ToString(), savePath.Path.Replace("{InstallDir}/", "")), localPath);
|
||||
var actualPath = Environment.ExpandEnvironmentVariables(savePath.Path.Replace('/', Path.DirectorySeparatorChar).Replace("{InstallDir}", installDirectory));
|
||||
var relativePath = actualPath.Replace(installDirectory + Path.DirectorySeparatorChar, "");
|
||||
|
||||
if (Directory.Exists(actualPath))
|
||||
{
|
||||
AddDirectoryToZip(archive, relativePath, actualPath, savePath.Id);
|
||||
}
|
||||
else if (File.Exists(actualPath))
|
||||
{
|
||||
archive.AddEntry(Path.Combine(savePath.Id.ToString(), relativePath), actualPath);
|
||||
}
|
||||
|
||||
entries.Add(new SavePathEntry
|
||||
{
|
||||
ArchivePath = relativePath,
|
||||
ActualPath = actualPath.Replace(installDirectory, "{InstallDir}")
|
||||
});
|
||||
|
||||
savePath.Entries = entries;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -225,7 +237,11 @@ namespace LANCommander.SDK
|
|||
}
|
||||
#endregion
|
||||
|
||||
archive.AddEntry("_manifest.yml", ManifestHelper.GetPath(installDirectory));
|
||||
var tempManifest = Path.GetTempFileName();
|
||||
|
||||
File.WriteAllText(tempManifest, ManifestHelper.Serialize(manifest));
|
||||
|
||||
archive.AddEntry("_manifest.yml", tempManifest);
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
|
|
|
@ -43,13 +43,7 @@ namespace LANCommander.SDK.Helpers
|
|||
|
||||
Logger?.LogTrace("Attempting to write manifest to path {Destination}", destination);
|
||||
|
||||
var serializer = new SerializerBuilder()
|
||||
.WithNamingConvention(new PascalCaseNamingConvention())
|
||||
.Build();
|
||||
|
||||
Logger?.LogTrace("Serializing manifest");
|
||||
|
||||
var yaml = serializer.Serialize(manifest);
|
||||
var yaml = Serialize(manifest);
|
||||
|
||||
Logger?.LogTrace("Writing manifest file");
|
||||
|
||||
|
@ -58,6 +52,19 @@ namespace LANCommander.SDK.Helpers
|
|||
return destination;
|
||||
}
|
||||
|
||||
public static string Serialize(GameManifest manifest)
|
||||
{
|
||||
var serializer = new SerializerBuilder()
|
||||
.WithNamingConvention(new PascalCaseNamingConvention())
|
||||
.Build();
|
||||
|
||||
Logger?.LogTrace("Serializing manifest");
|
||||
|
||||
var yaml = serializer.Serialize(manifest);
|
||||
|
||||
return yaml;
|
||||
}
|
||||
|
||||
public static string GetPath(string installDirectory)
|
||||
{
|
||||
return Path.Combine(installDirectory, ManifestFilename);
|
||||
|
|
|
@ -48,5 +48,12 @@ namespace LANCommander.SDK
|
|||
public string Type { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool IsRegex { get; set; }
|
||||
public IEnumerable<SavePathEntry> Entries { get; set; }
|
||||
}
|
||||
|
||||
public class SavePathEntry
|
||||
{
|
||||
public string ArchivePath { get; set; }
|
||||
public string ActualPath { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue