You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
52 lines
1.8 KiB
using System.IO;
|
|
|
|
namespace Housing.Services;
|
|
|
|
public static class HousingSettingsPaths
|
|
{
|
|
public static string GetIniPath(string fileName)
|
|
{
|
|
return GetIniPath(
|
|
fileName,
|
|
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
|
AppContext.BaseDirectory,
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
|
|
}
|
|
|
|
internal static string GetIniPath(string fileName, string desktopDirectory,
|
|
string applicationDirectory, string localApplicationData)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(desktopDirectory))
|
|
{
|
|
throw new DirectoryNotFoundException("사용자 바탕화면 폴더를 찾을 수 없습니다.");
|
|
}
|
|
|
|
var settingsDirectory = Path.Combine(desktopDirectory, "Housing");
|
|
Directory.CreateDirectory(settingsDirectory);
|
|
var settingsPath = Path.Combine(settingsDirectory, fileName);
|
|
if (File.Exists(settingsPath))
|
|
{
|
|
return settingsPath;
|
|
}
|
|
|
|
// Older versions saved edited judgement limits separately from the bundled INI.
|
|
var legacyInspectionPath = Path.Combine(localApplicationData, "AMO Housing", fileName);
|
|
var sourcePath = fileName == "InspectionSettings.ini" && File.Exists(legacyInspectionPath)
|
|
? legacyInspectionPath
|
|
: Path.Combine(applicationDirectory, fileName);
|
|
|
|
if (File.Exists(sourcePath))
|
|
{
|
|
try
|
|
{
|
|
File.Copy(sourcePath, settingsPath, overwrite: false);
|
|
}
|
|
catch (IOException ex) when ((ex.HResult & 0xFFFF) is 80 or 183 && File.Exists(settingsPath))
|
|
{
|
|
// Another instance may have initialized the same file first.
|
|
}
|
|
}
|
|
|
|
return settingsPath;
|
|
}
|
|
}
|
|
|