]> git.sur5r.net Git - c128-kasse/blobdiff - src/config.c
Use unlink() instead of _sysremove(), cleanup makefile
[c128-kasse] / src / config.c
index 523e8e445d8c2b266ab2bae5c2ab6524cbb9ed4e..b1e6a5816be8c8ecc89d5ab7289b5f148cf7d7df 100644 (file)
@@ -1,3 +1,9 @@
+/* 
+ * RGB2R-C128-Kassenprogramm
+ * (c) 2007 phil_fry, sECuRE, sur5r
+ * See LICENSE for license information
+ *
+ */
 #define _IS_CONFIG_C
 
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <unistd.h>
+
+#include "kasse.h"
 #include "general.h"
 #include "config.h"
 
 /* undocumented function which scratches files */
-unsigned char __fastcall__ _sysremove(const char *name);
+//unsigned char __fastcall__ _sysremove(const char *name);
 
 unsigned long int money = 0;
 unsigned long int items_sold = 0;
 BYTE printer_port = 4;
-static bool files_existing = false;
+static bool items_exists = false;
+static bool credits_exists = false;
 struct status_array_t status;
 struct credits_array_t credits;
 
@@ -24,47 +34,53 @@ struct credits_array_t credits;
  * files directly)
  *
  */
-bool lookup_needed_files() {
+static void lookup_needed_files() {
        BYTE lfn = 8;
-       BYTE files_existing = 0;
        struct cbm_dirent *dirent;
 
        if (cbm_opendir(lfn, (BYTE)8) != 0) {
                cprintf("could not open directory\r\n");
-               return false;
+               return;
+       }
+       while (cbm_readdir(lfn, dirent) == 0) {
+               if (strncmp(dirent->name, "log", 3) == 0)
+                       log_num++;
+               if (strcasecmp(dirent->name, "items") == 0)
+                       items_exists = true;
+               if (strcasecmp(dirent->name, "credits") == 0)
+                       credits_exists = true;
        }
-       while (cbm_readdir(lfn, dirent) == 0)
-               if (    strcasecmp(dirent->name, "items") == 0 ||
-                       strcasecmp(dirent->name, "credits") == 0)
-                       files_existing++;
        cbm_closedir(lfn);
-       return (files_existing >= 2);
 }
 
 void load_items() {
-       if (files_existing)
+       if (items_exists)
                cbm_load("items", (BYTE)8, &status);
+       else
+               memset(&status, 0, sizeof(struct status_array_t));
 }
 
 void load_credits() {
-       if (files_existing)
+       if (credits_exists)
                cbm_load("credits", (BYTE)8, &credits);
+       else
+               memset(&credits, 0, sizeof(struct credits_array_t));
 }
 
 void save_items() {
-       if (files_existing)
-               _sysremove("items");
+       if (items_exists)
+               unlink("items");
        cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
-       files_existing = true;
+       items_exists = true;
 }
 
 void save_credits() {
-       if (files_existing)
-               _sysremove("credits");
+       if (credits_exists)
+               unlink("credits");
        cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
-       files_existing = true;
+       credits_exists = true;
 }
 
 void load_config() {
-       files_existing = lookup_needed_files();
+       lookup_needed_files();
 }