Skip to content

Commit

Permalink
Open files in file explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej123456789 committed Mar 27, 2024
1 parent e8cc277 commit 5f7f424
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 25 deletions.
6 changes: 3 additions & 3 deletions kern/gui.err
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ gui/gui.c(382): Warning! W303: Parameter 'argument' has been defined, but not re
gui/gui.c(391): Warning! W303: Parameter 'argument' has been defined, but not referenced
gui/gui.c(402): Warning! W303: Parameter 'argument' has been defined, but not referenced
gui/gui.c(422): Warning! W303: Parameter 'argument' has been defined, but not referenced
gui/gui.c(637): Warning! W118: Label 'keyboard_loop' has been defined but not referenced
gui/gui.c(636): Warning! W308: The function 'c_keyboard_loop' without prototyped parameters called
gui/gui.c(636): Note! I2002: 'c_keyboard_loop' defined in: io.h(28)
gui/gui.c(639): Warning! W118: Label 'keyboard_loop' has been defined but not referenced
gui/gui.c(638): Warning! W308: The function 'c_keyboard_loop' without prototyped parameters called
gui/gui.c(638): Note! I2002: 'c_keyboard_loop' defined in: io.h(28)
gui/argument.h(15): Warning! W202: Symbol 'LCG_MODULUS' has been defined, but not referenced
gui/argument.h(14): Warning! W202: Symbol 'LCG_INCREMENT' has been defined, but not referenced
gui/argument.h(13): Warning! W202: Symbol 'LCG_MULTIPLIER' has been defined, but not referenced
Expand Down
7 changes: 7 additions & 0 deletions kern/gui/argument.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static uint16_t LCG_MODULUS = 65535; // 2^31
#define EXPLORER_SIZE 5
#define HISTORY_SIZE 5
#define LINE_SIZE 60 /* len_x - 4 */
#define OPEN_LINE_SIZE 21
#define TEXT_SIZE 180 /* 36 (len_x - 4) * 5 (len_y - 11) */

/**
Expand All @@ -44,11 +45,17 @@ typedef struct
* TODO: make BBFS write file structure to RAM,
* implement read function for that,
* and don't use char arrays
*
* @param open_index index for `open` array
* @param open array containing name of a file to open
*/
typedef struct
{
int index;
char* files[EXPLORER_SIZE];

int open_index;
char open[OPEN_LINE_SIZE];
} FileExplorer;

/**
Expand Down
2 changes: 2 additions & 0 deletions kern/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ void start_gui(DISK diskA)
/* ------------ */

screen.windows[2].elements.button[0] = init_button(2, 3, 8, 2, BLUE, WHITE, "Search", NULL);
screen.windows[2].elements.button[1] = init_button(12, 3, 6, 2, BLUE, WHITE, "Open", NULL);

/* ------------ */

Expand Down Expand Up @@ -559,6 +560,7 @@ void start_gui(DISK diskA)

FileExplorer file_explorer_struct;
file_explorer_struct.index = 0;
file_explorer_struct.open_index = 0;

/* ------------ */

Expand Down
140 changes: 118 additions & 22 deletions kern/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ uint16_t format_color(uint16_t background_color, uint16_t foreground_color)
void keyboard_event(Screen* screen)
{
bool dont_draw = false; /* we are clicking one of paint's button if true, we are not drawing */
bool dont_write = false; /* we are clicking save button in notepad, do not enter '\r\n' in text variable */
bool dont_write = false; /* we are clicking save button in notepad if true, do not enter '\r\n' in text variable */

Window* current_window = &screen->windows[screen->active_window];

Expand Down Expand Up @@ -279,35 +279,109 @@ void keyboard_event(Screen* screen)
/* Perform actions of file explorer's window */
else if (screen->active_window == 2)
{
move_cursor(current_window->x + 2, global_cursor.y + 2);
printf("FAT: \r\n");
move_cursor(current_window->x + 2, global_cursor.y + 1);

FAT_File far* fd = FAT_Open(&screen->diskA, "/");
FAT_DirectoryEntry entry;
int i = 0;
while (FAT_ReadEntry(&screen->diskA, fd, &entry) && i++ < 5)

/* Search button */
if (j == 0)
{
printf(" ");
for (int i = 0; i < 11; i++)
putc(entry.Name[i]);
move_cursor(current_window->x + 2, global_cursor.y + 2);
printf("FAT: \r\n");
move_cursor(current_window->x + 2, global_cursor.y + 1);

int i = 0;
while (FAT_ReadEntry(&screen->diskA, fd, &entry) && i++ < 5)
{
printf(" ");
for (int i = 0; i < 11; i++)
putc(entry.Name[i]);

printf("\r\n");
move_cursor(current_window->x + 2, global_cursor.y + 1);
}
FAT_Close(fd);

/* -------------------- */

printf("\r\n");
printf("BBFS v2: \r\n");
move_cursor(current_window->x + 2, global_cursor.y + 1);

for (int i = 0; i < screen->argument->file_explorer->index; i++)
{
printf(" %s\r\n", screen->argument->file_explorer->files[i]);
move_cursor(current_window->x + 2, global_cursor.y + 1);
}
}
FAT_Close(fd);

/* -------------------- */
/* Open button */
else if (j == 1)
{
char file_system[5];
char path[OPEN_LINE_SIZE - 5];

printf("BBFS v2: \r\n");
move_cursor(current_window->x + 2, global_cursor.y + 1);
screen->argument->file_explorer->open[screen->argument->file_explorer->open_index] = '\0';

for (int i = 0; i < screen->argument->file_explorer->index; i++)
{
printf(" %s\r\n", screen->argument->file_explorer->files[i]);
move_cursor(current_window->x + 2, global_cursor.y + 1);
for (int i = 0; i < screen->argument->file_explorer->open_index; i++)
{
if (i < 4)
{
file_system[i] = screen->argument->file_explorer->open[i];
}

file_system[5] = '\0';

if (i >= 4)
{
path[i - 4] = screen->argument->file_explorer->open[i];
}
}

path[screen->argument->file_explorer->open_index] = '\0';

char* file_system_str = file_system;
char* path_str = path;

if (strcmp(file_system_str, "fat/") == 0)
{
/* TODO */
}

else if (strcmp(file_system_str, "ram/") == 0)
{
bool found = false;

char temp[12];
for (int i = 0; i < screen->argument->file_explorer->index; i++)
{
strncpy(temp, screen->argument->file_explorer->files[i], 11);

char* tmp = temp;
if (strcmp(tmp, path_str) <= 0)
{
move_cursor(current_window->x + 2, global_cursor.y + 2);
printf("File: %s\r\n", screen->argument->file_explorer->files[i]);
move_cursor(current_window->x + 2, global_cursor.y + 1);

found = true;
break;
}
}

if (found == false)
{
move_cursor(current_window->x + 2, global_cursor.y + 2);
printf("File (%s) not found!", path_str);
move_cursor(current_window->x + 2, global_cursor.y + 1);
}
}

for (int i = 0; i < screen->argument->file_explorer->open_index; i++)
{
screen->argument->file_explorer->open[i] = ' ';
}

screen->argument->file_explorer->open_index = 0;
}

}

/* Perform actions of notepad's buttons */
Expand Down Expand Up @@ -456,8 +530,14 @@ void c_keyboard_loop(Screen* screen)
/* Update global cursor */
move_cursor(global_cursor.x - 1, global_cursor.y);

/* File explorer window */
if (screen->active_window == 2)
{
screen->argument->file_explorer->open_index--;
}

/* Notepad window */
if (screen->active_window == 3)
else if (screen->active_window == 3)
{
screen->argument->notepad->index--;
}
Expand All @@ -474,11 +554,27 @@ void c_keyboard_loop(Screen* screen)
/* Update global cursor (disabled because we are not printing a character) */
// move_cursor(global_cursor.x + 1, global_cursor.y);

/**
* If we are in file explorer window, print character.
* Otherwise, character printing is disabled as before.
*/
if (screen->active_window == 2)
{
printf("%c", ascii_code);
move_cursor(global_cursor.x + 1, global_cursor.y);

if (screen->argument->file_explorer->open_index != OPEN_LINE_SIZE - 1)
{
screen->argument->file_explorer->open[screen->argument->file_explorer->open_index] = ascii_code;
screen->argument->file_explorer->open_index++;
}
}

/**
* If we are in notepad window, print character.
* Otherwise, character printing is disabled as before.
*/
if (screen->active_window == 3)
else if (screen->active_window == 3)
{
printf("%c", ascii_code);
move_cursor(global_cursor.x + 1, global_cursor.y);
Expand Down

0 comments on commit 5f7f424

Please sign in to comment.