Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions AppsLab.CSharp.Exercises.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
10 changes: 10 additions & 0 deletions AppsPicker/AppsPicker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
207 changes: 207 additions & 0 deletions AppsPicker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
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<string> Apps = new List<string>();

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);
}
//ff ff ff ff