From e632a5393058671a71331ae0fad2789a201407f8 Mon Sep 17 00:00:00 2001 From: Taxes Date: Tue, 28 Oct 2025 19:47:55 +0100 Subject: [PATCH 1/3] Made the AppPicker --- AppsLab.CSharp.Exercises.sln | 15 +++ AppsPicker/AppsPicker.csproj | 10 ++ AppsPicker/Program.cs | 206 +++++++++++++++++++++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 AppsPicker/AppsPicker.csproj create mode 100644 AppsPicker/Program.cs diff --git a/AppsLab.CSharp.Exercises.sln b/AppsLab.CSharp.Exercises.sln index 1bacd373..a1442991 100644 --- a/AppsLab.CSharp.Exercises.sln +++ b/AppsLab.CSharp.Exercises.sln @@ -121,6 +121,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stuff", "Stuff", "{8899E3FF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Text to Font", "Text to Font\Text to Font.csproj", "{F8E65EA4-21D1-4C55-92C1-BF4246F7DDDE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppsPicker", "AppsPicker\AppsPicker.csproj", "{7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -803,6 +805,18 @@ Global {F8E65EA4-21D1-4C55-92C1-BF4246F7DDDE}.Release|x64.Build.0 = Release|Any CPU {F8E65EA4-21D1-4C55-92C1-BF4246F7DDDE}.Release|x86.ActiveCfg = Release|Any CPU {F8E65EA4-21D1-4C55-92C1-BF4246F7DDDE}.Release|x86.Build.0 = Release|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Debug|x64.ActiveCfg = Debug|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Debug|x64.Build.0 = Debug|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Debug|x86.ActiveCfg = Debug|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Debug|x86.Build.0 = Debug|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Release|Any CPU.Build.0 = Release|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Release|x64.ActiveCfg = Release|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Release|x64.Build.0 = Release|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Release|x86.ActiveCfg = Release|Any CPU + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -864,6 +878,7 @@ Global {93839192-1330-4DA2-8D69-C96D67B37DE7} = {8899E3FF-673C-4819-ACF9-28C65B2E2D52} {ECE162B8-50C0-43EC-B4E6-B4E909713007} = {8899E3FF-673C-4819-ACF9-28C65B2E2D52} {F8E65EA4-21D1-4C55-92C1-BF4246F7DDDE} = {8899E3FF-673C-4819-ACF9-28C65B2E2D52} + {7993C52E-0DC9-4728-AA7F-DA2299FDEA5E} = {8899E3FF-673C-4819-ACF9-28C65B2E2D52} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5BE04033-84E1-4A20-98B0-52043D7FFE41} diff --git a/AppsPicker/AppsPicker.csproj b/AppsPicker/AppsPicker.csproj new file mode 100644 index 00000000..2150e379 --- /dev/null +++ b/AppsPicker/AppsPicker.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/AppsPicker/Program.cs b/AppsPicker/Program.cs new file mode 100644 index 00000000..00135880 --- /dev/null +++ b/AppsPicker/Program.cs @@ -0,0 +1,206 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using System.IO; + +const string BaseFolder = @"C:\TestAppsC#"; +Directory.CreateDirectory(BaseFolder); +const string FileName = "apps.txt"; +string FilePath = Path.Combine(BaseFolder, FileName); + + + +List Apps = new List(); + +LoadApps(); + +int programRunning = 1; + +while (programRunning == 1) +{ + string Option = Options(); + Action(Option); + + string Options() + { + Console.WriteLine("Pick from these: \n(1) Add an app\n(2) Show all the apps\n(3) Find the app from the name\n(4) Delete an app\n(5) End the program"); + string? option = Console.ReadLine(); + return option?.Trim() ?? ""; + } + + void Action(string option) + { + switch (option) + { + case "1": + AddApp(); + break; + case "2": + ShowApps(); + break; + case "3": + FindApp(); + break; + case "4": + DeleteApp(); + break; + case "5": + EndProgram(); + break; + default: + Console.WriteLine("\nJust pick from 1–5, bro\n-------------"); + break; + } + } + + void AddApp() + { + Console.WriteLine("\nWhat app do you wanna add?\nTyping 'back' will send you back"); + string? raw = Console.ReadLine(); + string appApp = raw?.Trim() ?? ""; + + if (appApp.Equals("back", StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine(); + return; + } + + if (string.IsNullOrWhiteSpace(appApp)) + { + Console.WriteLine("Nothing was added"); + return; + } + + if (Apps.Any(a => a.Equals(appApp, StringComparison.OrdinalIgnoreCase))) + { + Console.WriteLine("It's already there"); + return; + } + + Apps.Add(appApp); + SaveApps(); + Console.WriteLine($"You added {appApp} to the apps list\n-------------"); + } + + void ShowApps() + { + if (Apps.Count == 0) + { + Console.WriteLine("\nNo apps added yet\n-------------"); + return; + } + + Console.WriteLine("\nHere are all the apps:"); + foreach (string app in Apps.OrderBy(a => a, StringComparer.OrdinalIgnoreCase)) + { + Console.WriteLine($"- {app}"); + } + Console.WriteLine("-------------"); + } + + void FindApp() + { + if (Apps.Count == 0) + { + Console.WriteLine("\nNo apps added yet\n-------------"); + return; + } + + Console.WriteLine("\nType the name of the app you want to find:\nTyping 'back' will send you back"); + string? raw = Console.ReadLine(); + string appName = raw?.Trim() ?? ""; + + if (string.IsNullOrEmpty(appName)) + { + Console.WriteLine("what chu doing bro?\n-------------"); + return; + } + + if (appName.Equals("back", StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine(); + return; + } + + bool found = Apps.Any(a => a.Equals(appName, StringComparison.OrdinalIgnoreCase)); + + Console.WriteLine(found + ? $"{appName} is in the apps list\n-------------" + : $"{appName} is not in the apps list\n-------------"); + } + + void DeleteApp() + { + if (Apps.Count == 0) + { + Console.WriteLine("\nNo apps added yet\n-------------"); + return; + } + + Console.WriteLine("\nType the name of the app you want to delete:\nTyping 'back' will send you back"); + string? raw = Console.ReadLine(); + string appName = raw?.Trim() ?? ""; + + if (string.IsNullOrEmpty(appName)) + { + Console.WriteLine("what chu doing bro?\n-------------"); + return; + } + + if (appName.Equals("back", StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine(); + return; + } + + string? match = Apps.FirstOrDefault(a => a.Equals(appName, StringComparison.OrdinalIgnoreCase)); + + if (match != null) + { + Apps.Remove(match); + SaveApps(); + Console.WriteLine($"{match} has been deleted from the apps list\n-------------"); + } + else + { + Console.WriteLine($"{appName} is not in the apps list\n-------------"); + } + } + + void EndProgram() + { + // Optional: Save again on exit just to be extra safe + SaveApps(); + Console.WriteLine("\nYou've ended the program"); + programRunning = 0; + } +} + +void LoadApps() +{ + if (!File.Exists(FilePath)) + return; + + // Read, trim, drop empties, and dedupe case-insensitively + var loaded = File.ReadLines(FilePath) + .Select(line => line.Trim()) + .Where(line => !string.IsNullOrWhiteSpace(line)) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToList(); + + if (loaded.Count > 0) + { + Apps = loaded; + Console.WriteLine($"Loaded {Apps.Count} apps from {FilePath}."); + } +} + +void SaveApps() +{ + // Simple write-all, one per line + // If you want to be extra careful: write to a temp and replace the original + var tmpPath = FilePath + ".tmp"; + File.WriteAllLines(tmpPath, Apps); + if (File.Exists(FilePath)) File.Delete(FilePath); + File.Move(tmpPath, FilePath); +} From bed3542d9510946a9bd5876f04ea4913ae21b009 Mon Sep 17 00:00:00 2001 From: Taxes Date: Tue, 28 Oct 2025 19:50:32 +0100 Subject: [PATCH 2/3] trying to make this work ig? --- AppsPicker/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AppsPicker/Program.cs b/AppsPicker/Program.cs index 00135880..40c8ec9c 100644 --- a/AppsPicker/Program.cs +++ b/AppsPicker/Program.cs @@ -204,3 +204,4 @@ void SaveApps() if (File.Exists(FilePath)) File.Delete(FilePath); File.Move(tmpPath, FilePath); } +//ff \ No newline at end of file From 573a8d2951f8c42f8a9f9dc90b2784e57f78e850 Mon Sep 17 00:00:00 2001 From: Taxes Date: Tue, 28 Oct 2025 19:53:37 +0100 Subject: [PATCH 3/3] work... --- AppsPicker/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppsPicker/Program.cs b/AppsPicker/Program.cs index 40c8ec9c..68b8a901 100644 --- a/AppsPicker/Program.cs +++ b/AppsPicker/Program.cs @@ -204,4 +204,4 @@ void SaveApps() if (File.Exists(FilePath)) File.Delete(FilePath); File.Move(tmpPath, FilePath); } -//ff \ No newline at end of file +//ff ff ff ff \ No newline at end of file