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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/Level-2.1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file added .vs/Level-2.1/v17/.wsuo
Binary file not shown.
12 changes: 12 additions & 0 deletions .vs/Level-2.1/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\ahmad\\OneDrive - IMAM ABDULRAHMAN BIN FAISAL UNIVERSITY\\CCSIT\\Assignments\\Level 2\\Level-2.1\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
8 changes: 8 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\src"
],
"SelectedNode": "\\src\\main.dart",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
110 changes: 109 additions & 1 deletion src/core/note_app.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,114 @@
import 'dart:ffi';

import 'utils.dart';
import 'dart:io';


/*this class takes care of the command-line user interface.
* @param path [String?]: is the file path
* @param choicePrompt [int?]: is responsible for Y/N operations
* @param fileSelectionFlag [bool]: a boolean variable that dictates a user's interest in selecting files.
* @param inFileOperationsFlag [bool]: a boolean variable that dictates a user's interest in manipulating a selected file.
*/

class NoteApp {
// TODO: Complete the run function
void run() {
print('Hello, world!');

String? path;

int? choicePrompt;
var binaryPrompt = {
1 : false,
2 : true
};

bool inFileOperationsFlag = true,
fileSelectionFlag = true;

while(fileSelectionFlag){
try{
inFileOperationsFlag = true;


print("\n-----------------------------------------------------------------------------------\n"
"Please Select One of The Following Operations:\n"
"1-Access File\n"
"2-Delete File\n"
"3-Exit program\n");
choicePrompt = int.parse(stdin.readLineSync()!);
switch(choicePrompt){


case(1):
print("Please insert file name and format [EX: dummyFile.txt]: ");
path = stdin.readLineSync()!;

if(!Note.exists(path)){
print("File not found... A new file will be created.");
}

Note.open(path, true);
break;

case(2):
print("Please insert file name and format [EX: dummyFile.txt]: ");
path = stdin.readLineSync()!;
Note.delete(path);
continue;

case(3):
inFileOperationsFlag = false;
fileSelectionFlag = false;
}



while (inFileOperationsFlag){
try{

print("\n-----------------------------------------------------------------------------------\n"
"Please Select One of The Following Operations:\n"
"1-Edit File\n"
"2-Select Another File\n"
"3-Exit Program\n");

choicePrompt = int.parse(stdin.readLineSync()!);

switch(choicePrompt){

case(1):
print("Do you wish to erase previous notes from file? [PRESS 1]: ");
Note.open(path!, binaryPrompt[int.parse(stdin.readLineSync()!)]);
print("-->");
Note.write(stdin.readLineSync()!);
break;
case(2):
inFileOperationsFlag = false;
break;
case(3):
inFileOperationsFlag = false;
fileSelectionFlag = false;
Note.close();
break;

}

}
catch(e){
print(e.toString() + "\n-----------------------------------------------------------------------------------");
}

}
}
catch(e){
e.toString();
}
}





}
}
67 changes: 66 additions & 1 deletion src/core/utils.dart
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
// TODO: Add any utility functions here
import 'dart:io';
// TODO: Add any utility functions here

//this class takes care of all logical IO operations
abstract class Note{
static var _file, _printer;

/*
*This method opens OR creates a file. If a file with the name [fileName] does not exist, it creates a new file named [fileName].
*
* @param fileName [String] : this variable embodies the file name and format. (EX: test.txt)
* @param append [bool] : this variable determines weather the file's previous content is wiped or appended to.
*/
static void open(String fileName, bool? append){
if(append == null)
append = true;

var mode = {
true : FileMode.append,
false : FileMode.write,
};

_file = File(fileName);
_printer = _file.openWrite(mode: mode[append]);

}

/*
* This method simply invokes File.write() method
*
* @param text [String]: is the text the user wants to write.
* */
static void write(String text){
try{
_printer.write(text + "\n");
}
catch(e){
throw("No File was Selected!");
}
}

//This method simply invokes File.delete
static void delete(String fileName) {
_find(fileName);
_file.delete();
}

//This method simply invokes File.existsSync
static bool exists(String fileName){
return File(fileName).existsSync();
}

//used when user desires to terminate program
static void close(){
_printer.flush();
_printer.close();
}

//this method prevents deletion-error by checking if file exists.
static void _find(String fileName){
if(exists(fileName))
_file = File(fileName);
else
throw("File not found!");
}
}
11 changes: 11 additions & 0 deletions src/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/* Ahmad Alsowayan 2220000086 Level-2.1
*
* Educational Resources Used:
* https://github.com/Programming-Club-IAU/Level-2.1
* https://www.fluttersolution.com/2023/04/understanding-access-modifiers-in-dart.html
* https://dart.dev/libraries/dart-io
* https://api.dart.dev/stable/3.4.0/dart-core/Error/throwWithStackTrace.html
* https://www.geeksforgeeks.org/dart-standard-input-output/
*
* */

import 'core/note_app.dart';

void main(List<String> args) {
Expand Down
2 changes: 2 additions & 0 deletions src/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello, CCSIT Club <3
My name is Ahmad Alsowayan