Beispiel #1
0
 private void UpdateJob(object DoValidate)
 {
     try
     {
         if (Mod is null)
         {
             Downloader.Update((bool)DoValidate);
         }
         else
         {
             Downloader.UpdateMod((bool)DoValidate, Mod.OriginID == 0UL ? Mod.ID : Mod.OriginID, Mod.ID);
         }
     }
     catch (Exception Exception)
     {
         Downloader.ReleaseLock();
         if (Exception is AggregateException)
         {
             Exception = Exception.InnerException;
         }
         if (Exception is ValidatorException)
         {
             Dispatcher.Invoke(() =>
             {
                 SetStatus(string.Format(LocString(LocCode.ValidatorExc), Exception.Message), DarkRed);
                 FinishHandler();
             });
         }
         else
         {
             WriteAllText($@"{AppDataFolder}\LastCrash.txt", $"{Exception.Message}\n{Exception.StackTrace}");
             Dispatcher.Invoke(() =>
             {
                 new CrashWindow(Exception).ShowDialog();
                 Current.Shutdown();
             });
         }
         return;
     }
 }
 private async void VerificationJob()
 {
     try
     {
         string ACFFile   = ACFPath;
         bool   ACFExists = Exists(ACFFile);
         if (ACF is null && ACFExists)
         {
             using (StreamReader Reader = new StreamReader(ACFFile))
                 ACF = new VDFStruct(Reader);
         }
         for (; ModIndex < Mods.Length; ModIndex++)
         {
             Dispatcher.Invoke(() => ModStatus.Text = string.Format(LocString(LocCode.MFVerifying), ModIndex + 1, Mods.Length, Mods[ModIndex].Name));
             ulong ID = Mods[ModIndex].ID, ManifestID = Downloader.UpdateMod(true, ID, ID);
             if (Finished)
             {
                 return;
             }
             if (await TryDeployAsync())
             {
                 await SteamAPI.SubscribeModAsync(ID);
             }
             if (!ACFExists)
             {
                 continue;
             }
             VDFStruct   ItemsInstalled = ACF["WorkshopItemsInstalled"], ItemDetails = ACF["WorkshopItemDetails"], IIEntry = ItemsInstalled?[ID.ToString()], IDEntry = ItemDetails?[ID.ToString()];
             ItemDetails Details = null;
             void GetItemDetails()
             {
                 if (!(Details is null))
                 {
                     return;
                 }
                 if (Connect())
                 {
                     List <ItemDetails> Response = GetDetails(ID);
                     if ((Response?.Count ?? 0) > 0)
                     {
                         Details = Response[0];
                     }
                 }
                 if (Details is null || Details.Result != 1)
                 {
                     throw new ValidatorException(LocString(LocCode.MIRequestFailed));
                 }
             }
             if (IIEntry is null)
             {
                 ACFChanged = true;
                 GetItemDetails();
                 IIEntry = new VDFStruct
                 {
                     Key      = ID.ToString(),
                     Children = new List <VDFStruct>
                     {
                         new VDFStruct {
                             Key = "size", Value = Details.Size.ToString()
                         },
                         new VDFStruct {
                             Key = "timeupdated", Value = Details.LastUpdated.ToString()
                         },
                         new VDFStruct {
                             Key = "manifest", Value = ManifestID.ToString()
                         }
                     }
                 };
                 if (ItemsInstalled != null)
                 {
                     ItemsInstalled.Children.Add(IIEntry);
                 }
             }
             else if (!ulong.TryParse(IIEntry["manifest"].Value, out ulong MID) || MID != ManifestID)
             {
                 ACFChanged = true;
                 GetItemDetails();
                 IIEntry["size"].Value        = Details.Size.ToString();
                 IIEntry["timeupdated"].Value = Details.LastUpdated.ToString();
                 IIEntry["manifest"].Value    = ManifestID.ToString();
             }
             if (IDEntry is null)
             {
                 ACFChanged = true;
                 GetItemDetails();
                 IDEntry = new VDFStruct
                 {
                     Key      = ID.ToString(),
                     Children = new List <VDFStruct>
                     {
                         new VDFStruct {
                             Key = "manifest", Value = ManifestID.ToString()
                         },
                         new VDFStruct {
                             Key = "timeupdated", Value = Details.LastUpdated.ToString()
                         },
                         new VDFStruct {
                             Key = "timetouched", Value = Now.ToUnixTimeSeconds().ToString()
                         },
                         new VDFStruct {
                             Key = "subscribedby", Value = Steam.ActiveUserID.ToString()
                         },
                     }
                 };
                 if (ItemDetails != null)
                 {
                     ItemDetails.Children.Add(IDEntry);
                 }
             }
             else if (!ulong.TryParse(IDEntry["manifest"].Value, out ulong MID) || MID != ManifestID)
             {
                 ACFChanged = true;
                 GetItemDetails();
                 IDEntry["manifest"].Value    = ManifestID.ToString();
                 IDEntry["timeupdated"].Value = Details.LastUpdated.ToString();
                 IDEntry["timetouched"].Value = Steam.ActiveUserID.ToString();
             }
         }
         await Dispatcher.Invoke(async() =>
         {
             Finished = true;
             TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
             ModStatus.Text = LocString(LocCode.MFVerificationComplete);
             if (ACFChanged)
             {
                 SetStatus(LocString(LocCode.MFApplyingModifications), YellowBrush);
                 if (!Steam.IsRunning)
                 {
                     using (StreamWriter Writer = new StreamWriter(ACFPath))
                         ACF.Write(Writer);
                 }
                 else if (ShowOptions("Info", LocString(LocCode.MFSteamRestartRequired)))
                 {
                     SetStatus(LocString(LocCode.WaitingForSteamShutdown), YellowBrush);
                     Retract();
                     Start($@"{Steam.Path}\Steam.exe", "-shutdown").WaitForExit();
                     while (Steam.IsRunning)
                     {
                         await Delay(1000);
                     }
                     using (StreamWriter Writer = new StreamWriter(ACFPath))
                         ACF.Write(Writer);
                     Start($@"{Steam.Path}\Steam.exe");
                 }
             }
             SetStatus(LocString(LocCode.MFSuccess), DarkGreen);
             Button.IsEnabled = false;
         });
     }
     catch (Exception Exception)
     {
         Downloader.ReleaseLock();
         if (Exception is AggregateException)
         {
             Exception = Exception.InnerException;
         }
         if (Exception is ValidatorException)
         {
             Dispatcher.Invoke(() =>
             {
                 SetStatus(string.Format(LocString(LocCode.ValidatorExc), Exception.Message), DarkRed);
                 FinishHandler();
             });
         }
         else
         {
             WriteAllText($@"{AppDataFolder}\LastCrash.txt", $"{Exception.Message}\n{Exception.StackTrace}");
             Dispatcher.Invoke(() =>
             {
                 new CrashWindow(Exception).ShowDialog();
                 Current.Shutdown();
             });
         }
         return;
     }
 }