Skip to content

Commit 38ae5b6

Browse files
committed
fix: 존재하지 않는 경로에 대해 FileVersionInfo.GetVersionInfo가 실행되지 않도록 가드 추가
1 parent 34d01ee commit 38ae5b6

File tree

1 file changed

+13
-6
lines changed
  • FocusTimer/Domain/Entities

1 file changed

+13
-6
lines changed

FocusTimer/Domain/Entities/App.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public static App FromExecutablePath(string path)
7474
throw new InvalidOperationException($"주어진 경로({path})로부터 App 엔티티를 생성할 수 없습니다. 해당 경로에 파일이 존재하지 않습니다.");
7575
}
7676

77-
var versionInfo = FileVersionInfo.GetVersionInfo(path);
78-
var title = GetAppTitle(versionInfo, path);
77+
var title = GetAppTitle(path);
7978
var icon = APIWrapper.ExtractAssociatedIcon(path);
8079

8180
return new App
@@ -86,10 +85,19 @@ public static App FromExecutablePath(string path)
8685
};
8786
}
8887

89-
private static string GetAppTitle(FileVersionInfo versionInfo, string path)
88+
private static string GetAppTitle(string path)
9089
{
9190
var logger = log4net.LogManager.GetLogger(typeof(App));
92-
91+
92+
if (!File.Exists(path))
93+
{
94+
// 3순위: 실행 파일 이름 (확장자 제외)
95+
return Path.GetFileNameWithoutExtension(path);
96+
}
97+
98+
// 이 호출은 주어진 경로의 파일이 존재하는 것이 확실할 때에만 수행해야 합니다.
99+
var versionInfo = FileVersionInfo.GetVersionInfo(path);
100+
93101
// 1순위: FileDescription
94102
if (!string.IsNullOrWhiteSpace(versionInfo.FileDescription))
95103
{
@@ -154,8 +162,7 @@ public void TryUpdateTitleIfEmpty()
154162
return;
155163
}
156164

157-
var versionInfo = FileVersionInfo.GetVersionInfo(ExecutablePath);
158-
Title = GetAppTitle(versionInfo, ExecutablePath);
165+
Title = GetAppTitle(ExecutablePath);
159166

160167
this.GetLogger().Info($"앱 '{ExecutablePath}'의 Title이 비어있어 자동으로 '{Title}'(으)로 업데이트했습니다.");
161168
}

0 commit comments

Comments
 (0)