From 1a176f2270e88ee633418368e53e49dc47cd0482 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 27 Feb 2020 18:53:46 -0600 Subject: [PATCH] Lots of path and file name issues resolved. --- singe/buildRelease.sh | 1 + singe/frameFile.c | 4 +- singe/indexing.xcf | 4 +- singe/magnifyingGlass.xcf | 4 +- singe/main.c | 11 +++-- singe/singe.c | 7 ++- singe/singe.pro | 89 ++++++++++++++++++++++++++--------- singe/util.c | 99 ++++++++++++++++++++++++++++++++++----- singe/util.h | 7 ++- singe/videoPlayer.c | 5 +- 10 files changed, 182 insertions(+), 49 deletions(-) diff --git a/singe/buildRelease.sh b/singe/buildRelease.sh index 4487cea3e..2cfdd60e4 100755 --- a/singe/buildRelease.sh +++ b/singe/buildRelease.sh @@ -91,6 +91,7 @@ doBuild Singe-Windows-x86_64 mingw 64 .exe rm /tmp/icon.ico rm /tmp/icon.png rm /tmp/singe.res +#cp ../build/mingw/64/Singe-Windows-x86_64.exe ../test/. # 32 Bit Raspbian echo -e "${G_L}\nLinux armv6\n${G_L}" diff --git a/singe/frameFile.c b/singe/frameFile.c index f0564bfa5..a47341bb5 100644 --- a/singe/frameFile.c +++ b/singe/frameFile.c @@ -125,7 +125,7 @@ int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Re // Get path where video files live path = utilReadLine(data, bytes, &offset); if (!path) utilDie("Cannot read video path from framefile!"); - utilFixPathSeparators(&path); + utilFixPathSeparators(&path, true); // If it's not an absolute path, pre-pend the path to the framefile if ((path[0] != utilGetPathSeparator()) && (path[1] != ':')) { @@ -136,7 +136,7 @@ int32_t frameFileLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Re memcpy(&path[count], temp, strlen(temp)); path[count + strlen(temp)] = 0; free(temp); - utilFixPathSeparators(&path); + utilFixPathSeparators(&path, true); count = 0; } diff --git a/singe/indexing.xcf b/singe/indexing.xcf index a86da9de2..f65810e8b 100644 --- a/singe/indexing.xcf +++ b/singe/indexing.xcf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4b71d81e254244c616fdbc92271a862c0a8d627c652206f83e620e69e1f5284d -size 54489 +oid sha256:5234e23c4b6e991941d3c344ecbe650780da21ad6379932b485fe1fa7c96a191 +size 53941 diff --git a/singe/magnifyingGlass.xcf b/singe/magnifyingGlass.xcf index 1503cf523..2d134a7bd 100644 --- a/singe/magnifyingGlass.xcf +++ b/singe/magnifyingGlass.xcf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:578e3ab359346a7d889aa610377a1237b0a8b117ca401798760ab57db52d12a6 -size 214488 +oid sha256:09f79c6cf6fda66cffc8f9d2c0b057b6e69e849b9791dedc910e720895ca9576 +size 215535 diff --git a/singe/main.c b/singe/main.c index 6befd53f5..572462d7d 100644 --- a/singe/main.c +++ b/singe/main.c @@ -326,6 +326,7 @@ int main(int argc, char *argv[]) { // Did we get a filename or path to open? if ((argc - argCount) != 1) showUsage(exeName, "No script file specified."); _confScriptFile = strdup(argv[argCount]); + utilFixPathSeparators(&_confScriptFile, false); // Exists? if (!utilFileExists(_confScriptFile)) { // Missing. Is a path? @@ -352,6 +353,7 @@ int main(int argc, char *argv[]) { // Do we need to generate a video name? if (_confVideoFile) { + utilFixPathSeparators(&_confVideoFile, false); if (!utilFileExists(_confVideoFile)) { free(_confVideoFile); _confVideoFile = NULL; @@ -392,6 +394,10 @@ int main(int argc, char *argv[]) { // Do we need to generate a data directory name? if (_confDataDir) { + utilFixPathSeparators(&_confDataDir, false); + // Try to create data directory to ensure it exists. + utilMkDirP(_confDataDir, 0777); + // Does it exist? if (!utilPathExists(_confDataDir)) { free(_confDataDir); _confDataDir = NULL; @@ -402,9 +408,6 @@ int main(int argc, char *argv[]) { if (x < 0) { x = 0; } - // All this temp nonsense here... - // I had just jammed a zero into _confDataDir at 'x' but then if utilFixPathSeparators - // calls realloc() it pooches things up. Weird. temp = strdup(_confScriptFile); temp[x] = 0; _confDataDir = strdup(temp); @@ -412,7 +415,7 @@ int main(int argc, char *argv[]) { temp = NULL; } if (!_confDataDir) showUsage(exeName, "Unable to locate data directory."); - utilFixPathSeparators(&_confDataDir); + utilFixPathSeparators(&_confDataDir, true); // Do they want tracing? if (tracing) { diff --git a/singe/singe.c b/singe/singe.c index f67ff35fd..a3eedcd39 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -1927,6 +1927,7 @@ void doIndexDisplay(int32_t percent) { } // Display animation + SDL_RenderSetLogicalSize(_renderer, screenW, screenH); SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 255); SDL_RenderClear(_renderer); @@ -1954,8 +1955,9 @@ void doIndexDisplay(int32_t percent) { // Update animation if (SDL_GetTicks() > nextUpdate) { + //angle += (SDL_GetTicks() - nextUpdate) / updateTicks; angle++; - if (angle > 359) angle = 0; + if (angle > 359) angle -= 360; nextUpdate = SDL_GetTicks() + updateTicks; } @@ -2390,6 +2392,8 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { // Mouse setup _mouseCount = ManyMouse_Init(); + //utilSay("***DEBUG*** Mouse Driver: %s", ManyMouse_DriverName()); + //utilSay("***DEBUG*** Mice Found: %d", _mouseCount); if (_mouseCount < 1) utilDie("No mice detected."); if (_mouseCount > MAX_MICE) { _mouseCount = MAX_MICE; @@ -2401,6 +2405,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { _mice[x].name[sizeof(_mice[x].name) - 1] = 0; _mice[x].x = (int32_t)(videoGetWidth(_videoHandle) * _overlayScaleX); _mice[x].y = (int32_t)(videoGetHeight(_videoHandle) * _overlayScaleY); + //utilSay("***DEBUG*** Mouse %d: %s", x, _mice[x].name); } SDL_SetWindowGrab(_window, SDL_TRUE); SDL_ShowCursor(SDL_DISABLE); diff --git a/singe/singe.pro b/singe/singe.pro index 69e8ab12d..1e6fe1bfc 100644 --- a/singe/singe.pro +++ b/singe/singe.pro @@ -55,15 +55,21 @@ platformPi:PLATFORM="pi" static { BUILDTHIRDARGS = \"$$PWD/thirdparty\" \"$$OUT_PWD/../thirdparty-build\" $$BITNESS $$PLATFORM $$LIBTYPE - win32 { - # Placeholder - doesn't work - BUILDTHIRD.commands = cmd.exe /c $$PWD\\preBuild.bat $$BUILDTHIRDARGS - } else { + + platformLinux { BUILDTHIRD.commands = bash $$PWD/preBuild.sh $$BUILDTHIRDARGS + BUILDTHIRD.target = this + PRE_TARGETDEPS += this + QMAKE_EXTRA_TARGETS += BUILDTHIRD + } + + platformPi { + message("No Pi support for building prereqs - yet.") + } + + platformMingw { + message("No Windows support for building prereqs - yet.") } - BUILDTHIRD.target = this - PRE_TARGETDEPS += this - QMAKE_EXTRA_TARGETS += BUILDTHIRD } # === Arg_Parser === @@ -101,9 +107,17 @@ QMAKE_CFLAGS += \ -isystem $$PWD/../thirdparty-build/$$PLATFORM/$$BITNESS/installed/include dynamic { + platformLinux { + message("No Linux support for building dynamically.") + } + platformPi { QMAKE_CFLAGS += -I/usr/include/lua5.3 } + + platformMingw { + message("No Windows support for building dynamically.") + } } HEADERS += \ @@ -136,16 +150,46 @@ SOURCES += \ LIBS += \ -L$$PWD/../thirdparty-build/$$PLATFORM/$$BITNESS/installed/lib \ -lpthread \ - -lXv \ - -lX11 \ - -lXext \ - -lm \ - -ldl \ - -lrt + -lm static { LIBS += \ -l:everything.a + + platformLinux { + LIBS += \ + -lXv \ + -lX11 \ + -lXext \ + -ldl \ + -lrt + } + + platformPi { + message("No direct Pi support yet.") + } + + platformMingw { + LIBS += \ + -mwindows \ + -static \ + -lmingw32 \ + -lbcrypt \ + -ldinput8 \ + -ldxguid \ + -ldxerr8 \ + -luser32 \ + -lgdi32 \ + -lwinmm \ + -limm32 \ + -lole32 \ + -loleaut32 \ + -lshell32 \ + -lsetupapi \ + -lversion \ + -luuid \ + -Dmain=SDL_main + } } dynamic { @@ -189,15 +233,16 @@ OTHER_FILES += \ buildRelease.sh \ singe.rc +platformLinux { + #QMAKE_POST_LINK += bash $$PWD/postLink.sh "$$PWD" "$$DESTDIR" "$$TARGET" -#linux:QMAKE_POST_LINK += bash $$PWD/postLink.sh "$$PWD" "$$DESTDIR" "$$TARGET" + # === Generate some data for our buildRelease script === -# === Generate some data for our buildRelease script === + FILEINFO = "SOURCES=\"$$SOURCES\"" \ + "HEADERS=\"$$HEADERS\"" \ + "LINUX_LIBS=\"$$LIBS\"" \ + "SOURCE_DIR=\"$$PWD\"" \ + "QMAKE_CFLAGS=\"$$QMAKE_CFLAGS\"" -FILEINFO = "SOURCES=\"$$SOURCES\"" \ - "HEADERS=\"$$HEADERS\"" \ - "LINUX_LIBS=\"$$LIBS\"" \ - "SOURCE_DIR=\"$$PWD\"" \ - "QMAKE_CFLAGS=\"$$QMAKE_CFLAGS\"" - -write_file("source.inc.sh", FILEINFO) + write_file("source.inc.sh", FILEINFO) +} diff --git a/singe/util.c b/singe/util.c index d876407d0..fa2a41d62 100644 --- a/singe/util.c +++ b/singe/util.c @@ -26,7 +26,11 @@ #include #include +#define ourMkdir(p,m) mkdir(p) + static const int CONSOLE_LINES = 1000; +#else +#define ourMkdir mkdir #endif @@ -101,27 +105,35 @@ bool utilFileExists(char *filename) { } -void utilFixPathSeparators(char **path) { +void utilFixPathSeparators(char **path, bool slash) { int32_t i = 0; - char *temp = *path; + char *work = *path; + char *temp = NULL; // Flip path separators to whatever our OS wants - while (temp[i] != 0) { - if (temp[i] == '\\' || temp[i] == '/') { - temp[i] = utilGetPathSeparator(); + while (work[i] != 0) { + if (work[i] == '\\' || work[i] == '/') { + work[i] = utilGetPathSeparator(); } i++; } - // Does this string end with a path separator? - if (temp[strlen(temp) - 1] != utilGetPathSeparator()) { - // No - append one. - temp = realloc(temp, sizeof(char) * (strlen(temp) + 1)); - temp[strlen(temp)] = utilGetPathSeparator(); - temp[strlen(temp) + 1] = 0; - *path = temp; + if (slash) { + // Does this string end with a path separator? + if (work[strlen(work) - 1] != utilGetPathSeparator()) { + // No - append one. + temp = strdup(work); + free(work); + work = malloc(sizeof(char) * (strlen(temp) + 1)); + strcpy(work, temp); + work[strlen(temp)] = utilGetPathSeparator(); + work[strlen(temp) + 1] = 0; + free(temp); + } } + + *path = work; } @@ -168,6 +180,67 @@ char utilGetPathSeparator(void) { } +bool utilMkDirP(const char *dir, const mode_t mode) { + char tmp[UTIL_PATH_MAX]; + char *p = NULL; + struct stat sb; + size_t len; + + // Make copy of dir. + len = strnlen(dir, UTIL_PATH_MAX); + if (len == 0 || len == UTIL_PATH_MAX) { + return -1; + } + memcpy(tmp, dir, len); + tmp[len] = '\0'; + + // Remove trailing slash. + if (tmp[len - 1] == utilGetPathSeparator()) { + tmp[len - 1] = '\0'; + } + + // Does it already exist? + if (stat(tmp, &sb) == 0) { + if (S_ISDIR (sb.st_mode)) { + return true; + } + } + + // Recursive mkdir. + for (p = tmp + 1; *p; p++) { + if (*p == utilGetPathSeparator()) { + *p = 0; + if (stat(tmp, &sb) != 0) { + // Does not exist - create it. + if (ourMkdir(tmp, mode) < 0) { + return false; + } + } else { + if (!S_ISDIR(sb.st_mode)) { + // Not a directory + return false; + } + } + *p = utilGetPathSeparator(); + } + } + // Check path + if (stat(tmp, &sb) != 0) { + // Does not exist - create it. + if (ourMkdir(tmp, mode) < 0) { + return false; + } + } else { + if (!S_ISDIR(sb.st_mode)) { + // Not a directory + return false; + } + } + + return true; +} + + bool utilPathExists(char *pathname) { DIR *dir = opendir(pathname); if (dir) { @@ -183,6 +256,8 @@ char *utilReadFile(char *filename, size_t *bytes) { FILE *in = fopen(filename, "rb"); size_t read = 0; + (void)read; + *bytes = 0; if (in) { diff --git a/singe/util.h b/singe/util.h index bf00c8cbc..b1587af81 100644 --- a/singe/util.h +++ b/singe/util.h @@ -26,11 +26,15 @@ #include #include +#include #include "common.h" +#define UTIL_PATH_MAX 1024 + + extern FILE *utilTraceFile; @@ -38,10 +42,11 @@ char *utilCreateString(char *format, ...); char *utilCreateStringVArgs(char *format, va_list args); void utilDie(char *fmt, ...); bool utilFileExists(char *filename); -void utilFixPathSeparators(char **path); +void utilFixPathSeparators(char **path, bool slash); char *utilGetFileExtension(char *filename); char *utilGetLastPathComponent(char *pathname); char utilGetPathSeparator(void); +bool utilMkDirP(const char *dir, const mode_t mode); bool utilPathExists(char *pathname); char *utilReadFile(char *filename, size_t *bytes); char *utilReadLine(char *haystack, size_t length, char **offset); diff --git a/singe/videoPlayer.c b/singe/videoPlayer.c index debd70441..9febeed73 100644 --- a/singe/videoPlayer.c +++ b/singe/videoPlayer.c @@ -148,7 +148,6 @@ int FFMS_CC _indexCallBack(int64_t current, int64_t total, void *ICPrivate) { thisPercent = (int32_t)((double)current / (double)total * 100.0); if (thisPercent != lastPercent) { lastPercent = thisPercent; - //utilSay("Indexing: %d%%", thisPercent); // GUI if (_indexingFunction) { _indexingFunction(thisPercent); @@ -175,7 +174,6 @@ FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool ha } } if (!index) { - //utilSay("Creating new index."); indexer = FFMS_CreateIndexer(filename, &v->errInfo); if (indexer == NULL) utilDie("%s", v->errInfo.Buffer); if (hasAudio) FFMS_TrackTypeIndexSettings(indexer, FFMS_TYPE_AUDIO, 1, 0); @@ -224,7 +222,7 @@ int32_t _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bo // Find video track v->videoTrack = FFMS_GetFirstTrackOfType(vIndex, FFMS_TYPE_VIDEO, &v->errInfo); if (v->videoTrack < 0) utilDie("%s", v->errInfo.Buffer); - v->videoSource = FFMS_CreateVideoSource(vFilename, v->videoTrack, vIndex, 1, FFMS_SEEK_NORMAL, &v->errInfo); + v->videoSource = FFMS_CreateVideoSource(vFilename, v->videoTrack, vIndex, -1, FFMS_SEEK_NORMAL, &v->errInfo); if (v->videoSource == NULL) utilDie("%s", v->errInfo.Buffer); // Get video properties @@ -260,6 +258,7 @@ int32_t _loadVideoAndAudio(char *vFilename, char *aFilename, char *indexPath, bo v->videoTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_TARGET, v->propFrame->EncodedWidth, v->propFrame->EncodedHeight); if (v->videoTexture == NULL) utilDie("%s", SDL_GetError()); if (!stretchVideo) { + //***TODO*** Is this the best place for this? What if we have videos of multiple sizes? SDL_RenderSetLogicalSize(renderer, v->propFrame->EncodedWidth, v->propFrame->EncodedHeight); }