From 425ca41e0891d366c1ede52fb565a68fb544a8a7 Mon Sep 17 00:00:00 2001 From: DjScribbles Date: Thu, 25 Feb 2016 15:09:27 -0500 Subject: [PATCH] Fixed Crash from Issue #1 Now if the associated directory is not present for an ACF file, it will report size 0, and will no longer crash when trying to copy, but the copy will still fail. --- GamePipeLib/Model/Steam/SteamApp.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/GamePipeLib/Model/Steam/SteamApp.cs b/GamePipeLib/Model/Steam/SteamApp.cs index 0dc1e96..ead83e4 100644 --- a/GamePipeLib/Model/Steam/SteamApp.cs +++ b/GamePipeLib/Model/Steam/SteamApp.cs @@ -42,6 +42,7 @@ public enum AppStateFlags public class SteamApp : GamePipeLib.Model.NotifyPropertyChangedBase, ISteamApplication { private System.IO.FileSystemWatcher _watcher; + private long _acfDiskSize; public SteamApp(string acfFilePath) { _AcfFile = acfFilePath; @@ -56,8 +57,13 @@ public void MeasureDiskSize() { if (!_isMeasured) { - var info = new DirectoryInfo(GameDir); - DiskSize = info.EnumerateFiles("*", SearchOption.AllDirectories).Sum(x => x.Length); + if (Directory.Exists(GameDir)) + { + var info = new DirectoryInfo(GameDir); + DiskSize = info.EnumerateFiles("*", SearchOption.AllDirectories).Sum(x => x.Length); + } + else + DiskSize = 0; _isMeasured = true; } } @@ -134,7 +140,12 @@ public void InitializeFromAcf() int count = 0; foreach (var pair in pairs) { - if (count >= 5) return; //return once we've got what we're looking for + if (count >= 5) + { + if (!Directory.Exists(GameDir)) + DiskSize = 0; + return; //return once we've got what we're looking for + } switch (pair.Item1.ToLower()) //Compare in lower case { case "appid": @@ -147,6 +158,7 @@ public void InitializeFromAcf() break; case "sizeondisk": DiskSize = long.Parse(pair.Item2); + _acfDiskSize = DiskSize; count++; break; case "name": @@ -187,7 +199,13 @@ public void RefreshFromAcf() count++; break; case "sizeondisk": - DiskSize = long.Parse(pair.Item2); + var newDiskSize = long.Parse(pair.Item2); + if (newDiskSize != _acfDiskSize) + { + DiskSize = newDiskSize; + _acfDiskSize = DiskSize; + _isMeasured = false; + } count++; break; }