src/DiscordBot/Utilities/LogMessages.cs
/// <summary>
/// Adds or removes an entry in a given storage file and returns true if the entry is toggled on
/// </summary>
/// <param name="entry">The line to add or remove from storage</param>
/// <returns>Returns true if added to storage, false if removed from storage</returns>
Adds or removes an entry in a given storage file and returns true if the entry is toggled on
Adds or removes an entry in a given storage file and returns true if the entry is toggled on
public static FileReturn ToggleStorageEntry(string path, string entry)
        {
            if (!File.Exists(path)) return FileReturn.FileDoesNotExist;
            List<string> storageList = File.ReadAllLines(path).ToList();
            if (storageList.Count == 0)
            {
                File.WriteAllText(path, entry);
                return FileReturn.EntryAdded;
            }
            int i = 0;
            FileReturn listStatus = FileReturn.EntryAdded;
            foreach (string storageEntry in storageList)
            {
                if (storageEntry == entry)
                {
                    storageList.RemoveAt(i);
                    listStatus = FileReturn.EntryRemoved;
                }
                i += 1;
            }
            if (listStatus == FileReturn.EntryAdded)
            {
                storageList.Add(entry);
            }
            File.WriteAllLines(path, storageList);
            return listStatus;
        }
public static FileReturn ToggleStorageEntry ( string path , string entry ) { if ( ! File . Exists ( path ) ) return FileReturn . FileDoesNotExist ; List < string > storageList = File . ReadAllLines ( path ) . ToList ( ) ; if ( storageList . Count == 0 ) { File . WriteAllText ( path , entry ) ; return FileReturn . EntryAdded ; } int i = 0 ; FileReturn listStatus = FileReturn . EntryAdded ; foreach ( string storageEntry in storageList ) { if ( storageEntry == entry ) { storageList . RemoveAt ( i ) ; listStatus = FileReturn . EntryRemoved ; } i += 1 ; } if ( listStatus == FileReturn . EntryAdded ) { storageList . Add ( entry ) ; } File . WriteAllLines ( path , storageList ) ; return listStatus ; }
Adds or removes an entry in a given storage file and returns true if the entry is toggled on
Adds or removes an entry in a given storage file and returns true if the entry is toggled on
// Go through all entries and remove the ones that match, if any. // If the entry is already in storage, delete it. // Adds the entry to the list if it does not exist. // Write the changes to storage.
Returns true if added to storage, false if removed from storage
Returns true if added to storage false if removed from storage
path
string
<not_specific>
entry
string
The line to add or remove from storage
The line to add or remove from storage