more fixes to Updater

This commit is contained in:
2018-12-28 16:09:42 +01:00
parent b50e04ea8c
commit 7f521b6b94

View File

@@ -276,11 +276,6 @@ namespace RothenburgAR.Updater
private IEnumerator CheckFiles()
{
//+ create file list
//+ run updatemedia sequentially
//+ write to cache until all subfiles are here, then to filesystem
//+ use progressbar
var usedFileList = new Dictionary<string, FileDownloadInfo>();
GenerateUsedFileList(usedFileList);
@@ -293,6 +288,7 @@ namespace RothenburgAR.Updater
foreach (var item in data)
{
if (!Directory.Exists(fileInfo.directory)) Directory.CreateDirectory(fileInfo.directory);
File.WriteAllBytes(item.Key, item.Value);
}
}
@@ -326,18 +322,7 @@ namespace RothenburgAR.Updater
}
}
//var rootDir = new DirectoryInfo(PathHelper.ExhibitionPath);
//var exhibitionDirs = rootDir.GetDirectories().ToList();
//foreach (var dir in exhibitionDirs)
//{
// var versionFilePath = Path.Combine(dir.FullName, "version.txt");
// if (!File.Exists(versionFilePath)) continue;
// var trackerFilePath = Path.Combine(dir.FullName, trackerMainFile);
// TODO I dont know the URL of trackers
// downloadList.Add(trackerFilePath);
//}
// would check for || d.Tracker.Status == VersionStatus.ok as well but we don't get an updateUrl for those so it's no use
var updatedTracker = VersionAnswer.Data.Where(d => d.Tracker.Status == VersionStatus.updated).ToList();
foreach (var exhibition in updatedTracker)
{
@@ -375,7 +360,6 @@ namespace RothenburgAR.Updater
private IEnumerator DownloadFile(FileDownloadInfo info, Dictionary<string, byte[]> data)
{
// create dir if nonexistent
if (!Directory.Exists(info.directory)) Directory.CreateDirectory(info.directory);
var eTag = GenerateETag(info.filepath);
@@ -418,10 +402,9 @@ namespace RothenburgAR.Updater
var test = http.Request.GetResponseHeaders();
if (subfilesHeader != null)
{
var subfiles = subfilesHeader.Split(new string[1] { ";;" }, StringSplitOptions.RemoveEmptyEntries);
var subfiles = subfilesHeader.Split(new string[1] { ";;" }, StringSplitOptions.RemoveEmptyEntries).ToList();
//TODO: will add already downloaded files to maxValue, fix by filtering?
ProgressBar.maxValue += subfiles.Length;
ProgressBar.maxValue += subfiles.Count(subfileName => !data.Keys.Contains(Path.Combine(info.directory, subfileName)));
foreach (var subfileName in subfiles)
{
@@ -431,7 +414,8 @@ namespace RothenburgAR.Updater
info.directory);
var subfileETag = GenerateETag(info.filepath);
if (!data.ContainsKey(subfileInfo.filepath))
// HACK to prevent infinite subfile loop
if (!data.ContainsKey(subfileInfo.filepath) && subfileName != "brick.png")
{
yield return DownloadFile(subfileInfo, subfileETag, data);
}
@@ -469,12 +453,12 @@ namespace RothenburgAR.Updater
{
var requiredMedia = ExhibitMetas.Values.ToList().SelectMany(m => m.SelectMany(i => i.Pois.Select(p => p.MediaId))).Where(m => m != null).Distinct().ToList();
var rootDir = new DirectoryInfo(PathHelper.MediaPath);
var exhibitionDirs = rootDir.GetDirectories().ToList();
foreach (var dir in exhibitionDirs)
var mediaDir = new DirectoryInfo(PathHelper.MediaPath);
var mediaDirs = mediaDir.GetDirectories().ToList();
foreach (var dir in mediaDirs)
{
// HACK to preserve passion media files
if (!requiredMedia.Contains(dir.Name) && Regex.IsMatch(dir.Name, "/[0-9]/"))
// HACK to preserve passion media files
if (!requiredMedia.Contains(dir.Name) && Regex.IsMatch(dir.Name, "[0-9]"))
{
Directory.Delete(dir.FullName, true);
}