Use working directory for all file accesses, some old file accesses always used the executable directory

This commit is contained in:
Adam Honse 2020-09-06 12:56:20 -05:00
parent 3e62c91ed3
commit 1f1548929d
2 changed files with 2 additions and 28 deletions

View file

@ -30,24 +30,11 @@ void DetectLEDStripControllers(std::vector<RGBController*> &rgb_controllers)
LEDStripController* new_ledstrip;
RGBController_LEDStrip* new_controller;
//Get file path in executable directory
std::ifstream infile;
char filename[2048];
char arg1[64];
#ifdef WIN32
GetModuleFileName(NULL, filename, 2048);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "\\ledstrip.txt");
#else
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "/ledstrip.txt");
#endif
//Open settings file
infile.open(filename);
infile.open("ledstrip.txt");
if (infile.good())
{

View file

@ -35,22 +35,9 @@ void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
{
RGBController_E131* new_controller;
//Get file path in executable directory
std::ifstream infile;
char filename[2048];
char arg1[64];
#ifdef WIN32
GetModuleFileName(NULL, filename, 2048);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "\\e131.txt");
#else
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "/e131.txt");
#endif
E131Device dev;
std::vector<E131Device> devices;
@ -66,7 +53,7 @@ void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
dev.matrix_height = 0;
//Open settings file
infile.open(filename);
infile.open("e131.txt");
if (infile.good())
{