public void AddAccount(string accountName) { var existingAccount = Accounts.FirstOrDefault(acc => acc.AccountName == accountName); if (existingAccount != null) { Log.WriteLine("Account already exists: " + accountName, LogType.Debug, "CollectionTracker.PluginSettings"); SetActiveAccount(accountName); return; } string accountFilePath = Path.Combine(HearthstoneCollectionTrackerPlugin.PluginDataDir, "Collection_" + accountName.GetValidFileName()); if (File.Exists(accountFilePath + ".xml")) { string basicFilePath = accountFilePath; string pathWithExtension; int i = 0; do { ++i; accountFilePath = basicFilePath + i; pathWithExtension = accountFilePath + ".xml"; } while (File.Exists(pathWithExtension) || Accounts.Any(acc => acc.FileStoragePath == pathWithExtension)); } AccountSummary newAccount = new AccountSummary() { AccountName = accountName, FileStoragePath = accountFilePath + ".xml" }; Accounts.Add(newAccount); }