~ruther/CTU-FEE-B0B35APO-Semestral-project

dabe7a399fb6329c39d6d7ca629e34a4fb019f97 — František Boháček 3 years ago 9f2b7d5
feat: add default options, load options on startup
2 files changed, 50 insertions(+), 5 deletions(-)

M file-browser/include/options.h
M file-browser/src/main.c
M file-browser/include/options.h => file-browser/include/options.h +2 -0
@@ 29,3 29,5 @@ file_operation_error_t exec_options_loader_load(exec_options_loader_t *loader, c

file_operation_error_t exec_options_save(exec_options_t *options, char *filename);
char *exec_options_get_program(exec_options_t *options, char *mime);

extern exec_options_t *browser_exec_options;

M file-browser/src/main.c => file-browser/src/main.c +48 -5
@@ 1,7 1,9 @@
#include <stdlib.h>
#include <stdio.h>

#include "file_access.h"
#include "file_browser.h"
#include "options.h"
#include "font.h"
#include "logger.h"
#include "mzapo_pheripherals.h"


@@ 18,19 20,22 @@
// text, který bude default

// TODO: okna
//   initial - lokální fs nebo nějaký unmounted
//   browser - ukazuje current složku, v ní soubory a info o nich, nahoře název
//     složky
//   contextmenu - ukazuje info o souboru a jeho nabídku na smazání, přesunutí,
//DONE   initial - lokální fs nebo nějaký unmounted
//DONE   browser - ukazuje current složku, v ní soubory a info o nich, nahoře název
//DONE     složky
//WIP   contextmenu - ukazuje info o souboru a jeho nabídku na smazání, přesunutí,
//     zkopírování, zobrazení v textovém move/copy - slouží podobně jako initial a
//     browser, ale k přesunutí nebo
//     zkopírování objektu
//   options - nastavení nabídka
//     mimetypes - jaký mime type otevírá co, defaultně dát jen pár mime types s možností přidat přes stdin (příp. virtuální klávesnici, když zbude čas)
//   dialog

// TODO: dokončit dokumentaci

// options, browser, contextmenu
// options, contextmenu
// TODO: dialog s chybou
// TODO: seřazení souborů, aby . a .. byly první
// spouštění souborů // 15 - 16

// dokončit dokumentaci a vygenerovat doxygen - úterý


@@ 40,8 45,27 @@
typedef enum {
  ERROR_SUCCESS,
  ERROR_PHERIPHERALS,
  ERROR_OPTIONS,
} error_t;

#define OPTIONS_PATH "eoptions.cfg"

void exec_options_create_default() {
  exec_option_t options_arr[] = {
      {.mime = "image/png", .program = "./bin/image-viewer"},
      {.mime = "image/jpeg", .program = "./bin/image-viewer"},
      {.mime = "image/x-portable-pixmap", .program = "./bin/image-viewer"},
      {.mime = "image/x-portable-anymap", .program = "./bin/image-viewer"},
      {.mime = "text", .program = "./bin/text-viewer"},
  };
  exec_options_t options = {
    .options_count = sizeof(options_arr) / sizeof(options_arr[0]),
    .options = options_arr,
  };

  exec_options_save(&options, OPTIONS_PATH);
}

int main(int argc, char *argv[]) {
  #ifdef COMPUTER
  mzapo_sdl_init();


@@ 51,6 75,25 @@ int main(int argc, char *argv[]) {
  logger_t logger =
      logger_create(LOG_DEBUG, stdout, stdout, stderr, stderr, NULL);

  exec_options_loader_t loader = exec_options_loader_create(OPTIONS_PATH);
  file_operation_error_t error = exec_options_loader_get_size(&loader);

  char exec_buffer[loader.bytes_size];

  if (error == FILOPER_SUCCESS) {
    error = exec_options_loader_load(&loader, exec_buffer);
  }

  if (error == FILOPER_DOES_NOT_EXIST) {
    exec_options_create_default();
  }

  if (error != FILOPER_SUCCESS) {
    fileaccess_log_error(&logger, error);
    return ERROR_OPTIONS;
  }
  browser_exec_options = loader.exec_options;

  /* Try to acquire lock the first */
  if (serialize_lock(1) <= 0) {
    logger_warn(&logger, __FILE__, __FUNCTION__, __LINE__, "System is occupied");

Do not follow this link