#include <SDL2/SDL.h> #include "prefs.h"#include "printsdlerror.h"#include "util.h" /*Copyright (c) 2013-2021 Devine Lu Linvega2018 web port by rezmason2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for anypurpose with or without fee is hereby granted, provided that the abovecopyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS SOFTWARE.*/ static char *_prefPath = NULL;static void *_ptr;static size_t _size; voidPrefs_Init(const char *org, const char *app, void *ptr, size_t size){ char *prefPath; SDL_Init(0); prefPath = SDL_GetPrefPath(org, app); _prefPath = concat(prefPath, "prefs"); free(prefPath); SDL_Quit(); _ptr = ptr; _size = size;} voidPrefs_Quit(){ free(_prefPath); _prefPath = NULL;} voidPrefs_Reset(){ SDL_RWops *file = SDL_RWFromFile(_prefPath, "wb"); SDL_RWclose(file); /* printf("Clobbered the prefs file.\n"); */} voidPrefs_Load(){ SDL_RWops *file = SDL_RWFromFile(_prefPath, "rb"); SDL_ClearError(); if(file == NULL) { printf("Prefs error: prefs file not found.\n"); } else { if((long)_size != file->size(file)) { printf("Prefs error: prefs file is invalid; ignoring.\n"); } else if(SDL_RWread(file, _ptr, _size, 1) == 0) { printSDLError("SDL could not read the prefs file."); } SDL_RWclose(file); }} voidPrefs_Save(){ SDL_RWops *file = SDL_RWFromFile(_prefPath, "wb"); if(file == NULL) { printSDLError("SDL could not write the prefs file."); return; } SDL_RWwrite(file, _ptr, _size, 1); SDL_RWclose(file);}
#include <SDL2/SDL.h>
#include "prefs.h"
#include "printsdlerror.h"
#include "util.h"
/*
Copyright (c) 2013-2021 Devine Lu Linvega
2018 web port by rezmason
2021 C89 port by rezmason
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
static char *_prefPath = NULL;
static void *_ptr;
static size_t _size;
void
Prefs_Init(const char *org, const char *app, void *ptr, size_t size)
{
char *prefPath;
SDL_Init(0);
prefPath = SDL_GetPrefPath(org, app);
_prefPath = concat(prefPath, "prefs");
free(prefPath);
SDL_Quit();
_ptr = ptr;
_size = size;
}
void
Prefs_Quit()
{
free(_prefPath);
_prefPath = NULL;
}
void
Prefs_Reset()
{
SDL_RWops *file = SDL_RWFromFile(_prefPath, "wb");
SDL_RWclose(file);
/* printf("Clobbered the prefs file.\n"); */
}
void
Prefs_Load()
{
SDL_RWops *file = SDL_RWFromFile(_prefPath, "rb");
SDL_ClearError();
if(file == NULL) {
printf("Prefs error: prefs file not found.\n");
} else {
if((long)_size != file->size(file)) {
printf("Prefs error: prefs file is invalid; ignoring.\n");
} else if(SDL_RWread(file, _ptr, _size, 1) == 0) {
printSDLError("SDL could not read the prefs file.");
}
SDL_RWclose(file);
}
}
void
Prefs_Save()
{
SDL_RWops *file = SDL_RWFromFile(_prefPath, "wb");
if(file == NULL) {
printSDLError("SDL could not write the prefs file.");
return;
}
SDL_RWwrite(file, _ptr, _size, 1);
SDL_RWclose(file);
}