Skip to content

Commit 8bfdc76

Browse files
committed
Rewriting and improving stuff
1 parent febb5c7 commit 8bfdc76

72 files changed

Lines changed: 1978 additions & 1812 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
0 Bytes
Binary file not shown.
1 KB
Binary file not shown.

.vs/APComputerScience-CreateTask-Assignment/v17/DocumentLayout.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"RelativeDocumentMoniker": "APComputerScience-CreateTask-Assignment\\Program.cs",
2525
"ToolTip": "C:\\Users\\Thinc\\source\\repos\\APComputerScience-CreateTask-Assignment\\APComputerScience-CreateTask-Assignment\\Program.cs",
2626
"RelativeToolTip": "APComputerScience-CreateTask-Assignment\\Program.cs",
27-
"ViewState": "AQIAAAAAAAAAAAAAAAAAAD8AAAA2AAAA",
27+
"ViewState": "AQIAAB8AAAAAAAAAAADwvzsAAAAoAAAA",
2828
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
2929
"WhenOpened": "2024-04-04T12:38:05.332Z",
3030
"EditorCaption": ""
Binary file not shown.
Binary file not shown.

APComputerScience-CreateTask-Assignment/Program.cs

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ public static void BookGrabber()
2121
{
2222
List<string> Books = new List<string>();
2323
string BookDir = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), $"Books"));
24-
foreach (string foldername in Directory.GetDirectories(BookDir))
24+
foreach (string folderPath in Directory.GetDirectories(BookDir))
2525
{
26-
Books.Add(foldername);
27-
Console.WriteLine(foldername.Replace(BookDir + "\\", ""));
26+
string folderName = new DirectoryInfo(folderPath).Name;
27+
Books.Add(folderName);
28+
Console.WriteLine(folderName);
2829
}
2930
}
3031
// Stack Overflow - javadch
@@ -50,58 +51,58 @@ public static void PageReader()
5051
string Book = Console.ReadLine();
5152
Book = CapitalizeWithSpaces(Book);
5253
Console.WriteLine(Book);
53-
if (Directory.Exists(Path.Combine(BookDir, Book)))
54-
{
55-
Console.WriteLine($"Book Selected {Book}");
56-
} else
54+
55+
if (!Directory.Exists(Path.Combine(BookDir, Book)))
5756
{
58-
int A = 0;
59-
int B = 0;
60-
while (A==B)
61-
{
62-
Console.Write("That was not a option, Try Again!: ");
63-
Book = Console.ReadLine();
64-
Book = CapitalizeWithSpaces(Book);
65-
if (Directory.Exists(Path.Combine(BookDir, Book)))
66-
{
67-
Console.WriteLine($"Book Selected {Book}");
68-
A++;
69-
}
70-
}
57+
Console.Write("The Options are above the prior line Which one of those?: ");
58+
Book = Console.ReadLine();
59+
Book = CapitalizeWithSpaces(Book);
60+
Console.WriteLine(Book);
7161
}
62+
7263
List<string> Pages = new List<string>();
73-
for (int i = 0; ; i++)
64+
int maxPages = 1000; // Adjust this number based on your expected maximum number of pages
65+
66+
for (int i = 0; i < maxPages; i++)
7467
{
75-
if (File.Exists(Path.Combine(BookDir, Book, $"{i}.txt")))
68+
string filePath = Path.Combine(BookDir, Book, $"{i}.txt");
69+
if (File.Exists(filePath))
7670
{
7771
Pages.Add(i.ToString());
7872
}
79-
else if (!File.Exists(Path.Combine(BookDir, Book, $"{i}.txt")))
80-
{
81-
break;
82-
}
8373
else
8474
{
85-
Console.WriteLine("No Pages Available or hit cap");
86-
break;
75+
break; // Exit the loop if no more pages are found
8776
}
8877
}
78+
79+
if (Pages.Count == 0)
80+
{
81+
Console.WriteLine("Error: No pages found for the selected book.");
82+
return;
83+
}
84+
8985
string saveFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Save.txt");
9086
bool BookFinishedForNow = false;
87+
9188
while (BookFinishedForNow == false)
9289
{
9390
if (File.Exists(saveFilePath))
9491
{
9592
string[] saveLines = File.ReadAllLines(saveFilePath);
93+
bool foundCurrentPage = false;
94+
9695
foreach (string line in saveLines)
9796
{
9897
if (line.StartsWith($"{Book}-Current-Page: "))
9998
{
99+
foundCurrentPage = true;
100100
string currentPageStr = line.Split(':')[1].Trim();
101101
if (int.TryParse(currentPageStr, out int currentPage))
102102
{
103103
if (currentPage >= 0 && currentPage <= Pages.Count)
104104
{
105+
// Display current page and handle navigation
105106
Console.Clear();
106107
Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
107108
Console.WriteLine($"Book: {Book}\nPage: {string.Join(", ", Pages.ElementAt(currentPage))}");
@@ -115,7 +116,7 @@ public static void PageReader()
115116
Console.Write("What Navigation would you like to do from the above options?: ");
116117
string Option = Console.ReadLine();
117118
Functions(Option, ref currentPage, ref BookFinishedForNow, Pages.Count);
118-
Save(ref saveLines, ref Book, ref saveFilePath, ref currentPage);
119+
Save(ref saveLines, ref Book, ref saveFilePath, ref currentPage, ref BookDir);
119120
}
120121
else
121122
{
@@ -129,6 +130,15 @@ public static void PageReader()
129130
break;
130131
}
131132
}
133+
134+
if (!foundCurrentPage)
135+
{
136+
// Add line to save file for the current book
137+
using (StreamWriter sw = File.AppendText(saveFilePath))
138+
{
139+
sw.WriteLine($"{Book}-Current-Page: 0");
140+
}
141+
}
132142
}
133143
else
134144
{
@@ -206,22 +216,34 @@ public static void Functions(string Option, ref int currentPage, ref bool BookFi
206216
}
207217
}
208218
}
209-
public static void Save(ref string[] saveLines, ref string Book, ref string saveFilePath, ref int currentPage)
219+
public static void Save(ref string[] saveLines, ref string Book, ref string SaveFilePath, ref int currentPage, ref string BookDir)
210220
{
211-
// Provided by GPT and modified from it to work better.
212-
string[] updatedSaveLines = new string[saveLines.Length];
221+
if (!Directory.Exists(BookDir))
222+
{
223+
Directory.CreateDirectory(BookDir);
224+
}
225+
226+
bool bookFound = false;
227+
213228
for (int i = 0; i < saveLines.Length; i++)
214229
{
215230
if (saveLines[i].StartsWith($"{Book}-Current-Page: "))
216231
{
217-
updatedSaveLines[i] = $"{Book}-Current-Page: {currentPage}";
232+
saveLines[i] = $"{Book}-Current-Page: {currentPage}";
233+
bookFound = true;
234+
break;
218235
}
219-
else
236+
}
237+
238+
if (!bookFound)
239+
{
240+
using (StreamWriter sw = File.AppendText(SaveFilePath))
220241
{
221-
updatedSaveLines[i] = saveLines[i];
242+
sw.WriteLine($"{Book}-Current-Page: {currentPage}");
222243
}
223244
}
224-
File.WriteAllLines(saveFilePath, updatedSaveLines);
245+
246+
File.WriteAllLines(SaveFilePath, saveLines);
225247
}
226248
}
227249
}

APComputerScience-CreateTask-Assignment/bin/Release/net8.0/Books/Harry Potter/0.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Chapter 1: The Boy Who Lived
2+
13
Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say
24
that they were perfectly normal, thank you very much. They were the last
35
people you'd expect to be involved in anything strange or mysterious,
@@ -28,4 +30,6 @@ starts, there was nothing about the cloudy sky outside to suggest that
2830
strange and mysterious things would soon be happening all over the
2931
country. Mr. Dursley hummed as he picked out his most boring tie for
3032
work, and Mrs. Dursley gossiped away happily as she wrestled a
31-
screaming Dudley into his high chair.
33+
screaming Dudley into his high chair.
34+
35+
None of them noticed a large, tawny owl flutter past the window.
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
None of them noticed a large, tawny owl flutter past the window.
1+
At half past eight, Mr. Dursley picked up his briefcase, pecked Mrs.
2+
Dursley on the cheek, and tried to kiss Dudley good-bye but missed,
3+
because Dudley was now having a tantrum and throwing his cereal at the
4+
walls. "Little tyke," chortled Mr. Dursley as he left the house. He got
5+
into his car and backed out of number four's drive.
6+
7+
It was on the corner of the street that he noticed the first sign of
8+
something peculiar -- a cat reading a map. For a second, Mr. Dursley
9+
didn't realize what he had seen -- then he jerked his head around to
10+
look again. There was a tabby cat standing on the corner of Privet
11+
Drive, but there wasn't a map in sight. What could he have been thinking
12+
of? It must have been a trick of the light. Mr. Dursley blinked and
13+
stared at the cat. It stared back. As Mr. Dursley drove around the
14+
corner and up the road, he watched the cat in his mirror. It was now
15+
reading the sign that said Privet Drive -- no, looking at the sign; cats
16+
couldn't read maps or signs. Mr. Dursley gave himself a little shake and
17+
put the cat out of his mind. As he drove toward town he thought of
18+
nothing except a large order of drills he was hoping to get that day.
19+
20+
But on the edge of town, drills were driven out of his mind by something
21+
else. As he sat in the usual morning traffic jam, he couldn't help
22+
noticing that there seemed to be a lot of strangely dressed people
23+
about. People in cloaks. Mr. Dursley couldn't bear people who dressed in
24+
funny clothes -- the getups you saw on young people! He supposed this
25+
was some stupid new fashion. He drummed his fingers on the steering
26+
wheel and his eyes fell on a huddle of these weirdos standing quite
27+
close by. They were whispering excitedly together. Mr. Dursley was
28+
enraged to see that a couple of them weren't young at all; why, that man
29+
had to be older than he was, and wearing an emerald-green cloak! The
30+
nerve of him! But then it struck Mr. Dursley that this was probably some
31+
silly stunt -- these people were obviously collecting for something...
32+
yes, that would be it. The traffic moved on and a few minutes later, Mr.
33+
Dursley arrived in the Grunnings parking lot, his mind back on drills.
234

3-
At half past eight, Mr. Dursley picked up his briefcase, pecked Mrs.
4-
Dursley on the cheek, and tried to kiss Dudley good-bye but missed,
5-
because Dudley was now having a tantrum and throwing his cereal at the
6-
walls. "Little tyke," chortled Mr. Dursley as he left the house. He got
7-
into his car and backed out of number four's drive.
8-
9-
It was on the corner of the street that he noticed the first sign of
10-
something peculiar -- a cat reading a map. For a second, Mr. Dursley
11-
didn't realize what he had seen -- then he jerked his head around to
12-
look again. There was a tabby cat standing on the corner of Privet
13-
Drive, but there wasn't a map in sight. What could he have been thinking
14-
of? It must have been a trick of the light. Mr. Dursley blinked and
15-
stared at the cat. It stared back. As Mr. Dursley drove around the
16-
corner and up the road, he watched the cat in his mirror. It was now
17-
reading the sign that said Privet Drive -- no, looking at the sign; cats
18-
couldn't read maps or signs. Mr. Dursley gave himself a little shake and
19-
put the cat out of his mind. As he drove toward town he thought of
20-
nothing except a large order of drills he was hoping to get that day.
21-
22-
But on the edge of town, drills were driven out of his mind by something
23-
else. As he sat in the usual morning traffic jam, he couldn't help
24-
noticing that there seemed to be a lot of strangely dressed people
25-
about. People in cloaks. Mr. Dursley couldn't bear people who dressed in
26-
funny clothes -- the getups you saw on young people! He supposed this
27-
was some stupid new fashion. He drummed his fingers on the steering
28-
wheel and his eyes fell on a huddle of these weirdos standing quite
29-
close by. They were whispering excitedly together. Mr. Dursley was
30-
enraged to see that a couple of them weren't young at all; why, that man
31-
had to be older than he was, and wearing an emerald-green cloak! The
32-
nerve of him! But then it struck Mr. Dursley that this was probably some
33-
silly stunt -- these people were obviously collecting for something...
34-
yes, that would be it. The traffic moved on and a few minutes later, Mr.
35-
Dursley arrived in the Grunnings parking lot, his mind back on drills.

0 commit comments

Comments
 (0)