Test code for full path

This commit is contained in:
mwalker33 2020-04-14 19:17:00 +10:00
parent a1976fd6fe
commit 0b43252a02
2 changed files with 54 additions and 6 deletions

View file

@ -23,7 +23,8 @@
#include <string.h>
#include "cmdparser.h"
#include <ctype.h>
#include <unistd.h>
// #include <unistd.h>
#include <proxmark3.h>
//#include "proxgui.h"
//extern void SetWindowsPosition (void);
@ -31,6 +32,14 @@ static int CmdHelp(const char *Cmd);
static int setCmdHelp(const char *Cmd);
// Load all settings into memory (struct)
#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
static char* prefGetFilename (void) {
/*
static char Buffer[FILENAME_MAX+sizeof(preferencesFilename)+2] = {0};
@ -45,7 +54,24 @@ static char* prefGetFilename (void) {
return Buffer;
*/
return preferencesFilename;
static char Buffer [FILENAME_MAX] = {0};
char *Path;
// int searchHomeFilePath(char **foundpath, const char *filename, bool create_home);
if (searchHomeFilePath(&Path,preferencesFilename,false) == PM3_SUCCESS) {
snprintf(Buffer,sizeof(Buffer)-1,"%s",Path);
} else {
snprintf(Buffer,sizeof(Buffer)-1,"%s",preferencesFilename);
}
//printf ("%s [%s]\n",Buffer,get_my_user_directory() );
// GetCurrentDir (Buffer,sizeof(Buffer));
// printf ("%s\n",Buffer, );
return Buffer;
//return preferencesFilename;
}
int preferences_load (void) {

View file

@ -29,8 +29,20 @@
#include "flash.h"
#include "preferences.h"
// mwalker33 test code
#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
// end test code
// Used to enable/disable use of preferences json file
// #define USE_PREFERENCE_FILE
#define USE_PREFERENCE_FILE
#ifdef _WIN32
@ -392,15 +404,25 @@ static void set_my_executable_path(void) {
static const char *my_user_directory = NULL;
// mwalker33 test code
static char _cwd_Buffer [FILENAME_MAX] = {0};
// end test code
const char *get_my_user_directory(void) {
return my_user_directory;
}
static void set_my_user_directory(void) {
my_user_directory = getenv("HOME");
// if not found, default to current directory
if (my_user_directory == NULL)
my_user_directory = ".";
if (my_user_directory == NULL) {
// mwalker33 test code
my_user_directory = GetCurrentDir ( _cwd_Buffer,sizeof( _cwd_Buffer));
// change all slashs to / (windows should not care...
for (int i = 0; i < strlen(_cwd_Buffer); i++)
if (_cwd_Buffer[i] == '\\') _cwd_Buffer[i] = '/';
// end
// my_user_directory = ".";
}
}
static void show_help(bool showFullHelp, char *exec_name) {