Minor improvements

Better error message on configuration error, cleaned up generated config, new "copy extras" code
This commit is contained in:
farfalleflickan 2022-10-31 12:39:51 +01:00
parent 908f67946c
commit e88d8972e2
No known key found for this signature in database
GPG Key ID: 6506CE3E020FAF59
4 changed files with 41 additions and 21 deletions

View File

@ -216,7 +216,7 @@ progConfig *getConfig(char *srcPath) {
mallocMacro(options->TMDBapi, tempPtrSize, "getConfig error");
strlcpy(options->TMDBapi, confValue, tempPtrSize);
} else {
fatalError_exit("getConfig error", "configuration file \"%s\" contains errors!\n%sUse \"cmyflix --gen-config > %s\" to generate default.\n", srcPath, HBLU, srcPath);
fatalError_exit("getConfig error", "configuration file \"%s\" contains errors!\nInvalid: \"%s\";\n%sUse \"cmyflix --gen-config > %s\" to generate default.\n", srcPath, confKey, HBLU, srcPath);
}
if (i<properties) {
pos+=offset[i]+offset[i+1];

View File

@ -206,27 +206,33 @@ void copyExtras(progConfig *conf, progFlags runFlags, char *htmlFolder, char *de
tempStr=dirname(conf->TVhtml);
}
if (tempStr!=NULL) {
char *cmdStr=NULL;
size_t tempStrSize=strlen("cp -r /* ")+strlen(extPath)+strlen(tempStr)+1;
mallocMacro(cmdStr, tempStrSize, "cmyflix error");
snprintf(cmdStr, tempStrSize, "cp -r %s/* %s", extPath, tempStr);
resetSTDColors();
FILE *cmdRet=popen(cmdStr, "r");
if (cmdRet==NULL) {
if (pclose(cmdRet)!=0) {
printError("cmyflix", false, HRED, "%s\n", strerror(errno));
}
tryFree(cmdStr);
fatalError_exit("cmyflix error", "something went wrong while trying to copy HTML resources from '%s' to '%s';\n", extPath, tempStr);
} else {
if (pclose(cmdRet)!=0) {
printError("cmyflix", false, HRED, "something went wrong while trying to copy HTML resources from '%s' to '%s';\n", extPath, tempStr);
printError("cmyflix", false, HRED, "%s\n", strerror(errno));
char *tempStr2=appendSlash(tempStr);
if (checkFolder(tempStr2, true)==0) {
char *cmdStr=NULL;
size_t tempStrSize=strlen("cp -r /* ")+strlen(extPath)+strlen(tempStr2)+1;
mallocMacro(cmdStr, tempStrSize, "cmyflix error");
snprintf(cmdStr, tempStrSize, "cp -r %s/* %s", extPath, tempStr2);
resetSTDColors();
FILE *cmdRet=popen(cmdStr, "r");
if (cmdRet==NULL) {
if (pclose(cmdRet)!=0) {
printError("cmyflix", false, HRED, "%s\n", strerror(errno));
}
tryFree(cmdStr);
fatalError_exit("cmyflix error", "something went wrong while trying to copy HTML resources from '%s' to '%s';\n", extPath, tempStr2);
} else {
printInfo("", false, "Copied HTML resources from '%s' to '%s';\n", extPath, tempStr);
if (pclose(cmdRet)!=0) {
printError("cmyflix", false, HRED, "something went wrong while trying to copy HTML resources from '%s' to '%s';\n", extPath, tempStr2);
printError("cmyflix", false, HRED, "%s\n", strerror(errno));
} else {
printInfo("", false, "Copied HTML resources from '%s' to '%s';\n", extPath, tempStr2);
}
}
}
tryFree(cmdStr);
tryFree(cmdStr);
}
if (tempStr2!=tempStr) {
tryFree(tempStr2);
}
} else {
printError("cmyflix error", false, HRED, "could not get path to copy HTML resources to.\n");
}
@ -403,7 +409,6 @@ int main(int argc, char * argv[]) {
printVersion();
exit(EXIT_SUCCESS);
} else if (currOption=='9') { // --gen-config
resetSTDColors();
printf("%s\n", DEF_CONF);
exit(EXIT_SUCCESS);
} else if (currOption=='c') { // --clean

View File

@ -983,3 +983,17 @@ long double getElapsedTime() {
gettimeofday(&currentTime, NULL);
return (currentTime.tv_sec - timeProgStart.tv_sec)+((long double)(currentTime.tv_usec - timeProgStart.tv_usec)/1000000);
}
// checks if last character in string is '/' and appends it if needed
char *appendSlash(char *origStr) {
char *newStr=NULL;
size_t origLen=strlen(origStr);
if (origStr[origLen]=='/') {
newStr=origStr;
} else {
origLen+=2;
mallocMacro(newStr, origLen, "cmyflix error");
snprintf(newStr, origLen, "%s/", origStr);
}
return newStr;
}

View File

@ -140,3 +140,4 @@ void printBitFlags(unsigned bits);
int fixMode(progConfig *conf, progFlags flags, const char *toFix, const char *id, const char *poster, const char *newName, bool refreshMode);
int writeCharToFile(const char *str, const char *fileStr);
long double getElapsedTime();
char *appendSlash(char *origStr);