From f81e7526451c2dc85d14130874e17e9c7372a976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=AB?= Date: Sat, 5 Sep 2020 11:36:00 +0800 Subject: [PATCH] fix crash if no workshop addons are present --- L4d2AddonsMgr.sln | 14 +++- .../AddonsLibrary/GameDirAddonsLibrary.cs | 10 ++- L4d2AddonsMgr/App.config | 2 +- L4d2AddonsMgr/L4d2AddonsMgr.csproj | 25 +++++- L4d2AddonsMgr/MainWindow.xaml | 6 ++ L4d2AddonsMgr/MainWindow.xaml.cs | 79 +++++++++++++++++-- .../Utils/DependencyObjectExtension.cs | 19 +++++ L4d2AddonsMgrTest/L4d2AddonsMgrTest.csproj | 2 + 8 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 L4d2AddonsMgr/Utils/DependencyObjectExtension.cs diff --git a/L4d2AddonsMgr.sln b/L4d2AddonsMgr.sln index 7b7897f..6075bda 100644 --- a/L4d2AddonsMgr.sln +++ b/L4d2AddonsMgr.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.168 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "L4d2AddonsMgr", "L4d2AddonsMgr\L4d2AddonsMgr.csproj", "{E66621F6-7012-4D61-A1CB-E054671DE59A}" EndProject @@ -15,17 +15,27 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {E66621F6-7012-4D61-A1CB-E054671DE59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E66621F6-7012-4D61-A1CB-E054671DE59A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E66621F6-7012-4D61-A1CB-E054671DE59A}.Debug|x64.ActiveCfg = Debug|x64 + {E66621F6-7012-4D61-A1CB-E054671DE59A}.Debug|x64.Build.0 = Debug|x64 {E66621F6-7012-4D61-A1CB-E054671DE59A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E66621F6-7012-4D61-A1CB-E054671DE59A}.Release|Any CPU.Build.0 = Release|Any CPU + {E66621F6-7012-4D61-A1CB-E054671DE59A}.Release|x64.ActiveCfg = Release|x64 + {E66621F6-7012-4D61-A1CB-E054671DE59A}.Release|x64.Build.0 = Release|x64 {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Debug|x64.ActiveCfg = Debug|x64 + {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Debug|x64.Build.0 = Debug|x64 {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Release|Any CPU.Build.0 = Release|Any CPU + {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Release|x64.ActiveCfg = Release|x64 + {1DFFC99A-5D2A-478B-A01D-7808C9682CFF}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/L4d2AddonsMgr/AddonsLibrary/GameDirAddonsLibrary.cs b/L4d2AddonsMgr/AddonsLibrary/GameDirAddonsLibrary.cs index e388513..63581e5 100644 --- a/L4d2AddonsMgr/AddonsLibrary/GameDirAddonsLibrary.cs +++ b/L4d2AddonsMgr/AddonsLibrary/GameDirAddonsLibrary.cs @@ -56,9 +56,13 @@ public bool MoveNext() { currentEnum.Dispose(); // Enumerate than list. // https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=netframework-4.8 - currentEnum = new DirectoryInfo( - Path.Combine(basePath, CommonConsts.AddonsWorkshopDirectoryName) - ).EnumerateFiles(CommonConsts.VpkFileSearchPattern).GetEnumerator(); + try { + currentEnum = new DirectoryInfo( + Path.Combine(basePath, CommonConsts.AddonsWorkshopDirectoryName) + ).EnumerateFiles(CommonConsts.VpkFileSearchPattern).GetEnumerator(); + }catch (IOException) { + return res; + } isEnumWorkshop = true; return currentEnum.MoveNext(); } diff --git a/L4d2AddonsMgr/App.config b/L4d2AddonsMgr/App.config index 731f6de..56efbc7 100644 --- a/L4d2AddonsMgr/App.config +++ b/L4d2AddonsMgr/App.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/L4d2AddonsMgr/L4d2AddonsMgr.csproj b/L4d2AddonsMgr/L4d2AddonsMgr.csproj index 0bc28ec..91481ff 100644 --- a/L4d2AddonsMgr/L4d2AddonsMgr.csproj +++ b/L4d2AddonsMgr/L4d2AddonsMgr.csproj @@ -8,7 +8,7 @@ WinExe L4d2AddonsMgr L4d2AddonsMgr - v4.6.1 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -37,6 +37,28 @@ L4d2AddonsMgr.App + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + true + ..\packages\Microsoft.PinYinConverter.1.0.0\lib\ChnCharInfo.dll @@ -119,6 +141,7 @@ + diff --git a/L4d2AddonsMgr/MainWindow.xaml b/L4d2AddonsMgr/MainWindow.xaml index acd7129..970dd97 100644 --- a/L4d2AddonsMgr/MainWindow.xaml +++ b/L4d2AddonsMgr/MainWindow.xaml @@ -206,6 +206,12 @@