Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create empty settings file if missing #9318

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion GitCommands/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,39 @@ static AppSettings()
return path;
});

bool newFile = CreateEmptySettingsFileIfMissing();

SettingsContainer = new RepoDistSettings(null, GitExtSettingsCache.FromCache(SettingsFilePath), SettingLevel.Unknown);

if (!File.Exists(SettingsFilePath))
if (newFile || !File.Exists(SettingsFilePath))
{
ImportFromRegistry();
}

MigrateAvatarSettings();
MigrateSshSettings();

return;

static bool CreateEmptySettingsFileIfMissing()
{
try
{
string dir = Path.GetDirectoryName(SettingsFilePath);
if (!Directory.Exists(dir) || File.Exists(SettingsFilePath))
{
return false;
}
}
catch (ArgumentException)
{
// Illegal characters in the filename
return false;
}

File.WriteAllText(SettingsFilePath, "<?xml version=\"1.0\" encoding=\"utf-8\"?><dictionary />", Encoding.UTF8);
return true;
}
}

/// <summary>
Expand Down