Menu fixed, path problems on Windows fixed. b14 released.

This commit is contained in:
Scott Duensing 2020-04-02 20:29:17 -05:00
parent 70da276a58
commit 127ac9891b
5 changed files with 105 additions and 74 deletions

View file

@ -29,69 +29,6 @@ function compareTitles(a, b)
end
function wrapText(text, maxWidth)
local words = {}
local line = ""
local lastLine = ""
local lastWord = ""
local newLine = false
local trimBreak = utilTrim(WRAP_BREAK)
-- Break input into words
for w in text:gmatch("%S+") do
words[#words+1] = w
end
-- Iterate over words and try to fit them in the space given
for _, word in ipairs(words) do
-- Add new word to line
lastLine = line
if newLine then
line = lastWord
newLine = false
end
line = utilTrim(line .. " " .. word)
-- Create a temporary sprite to see how wide this is
if string.len(line) > 0 then
spriteTemp = fontToSprite(line)
if spriteGetWidth(spriteTemp) > maxWidth or word == trimBreak then
-- Was the wrap forced?
if word == trimBreak then
word = ""
if spriteGetWidth(spriteTemp) <= maxWidth then
lastLine = lastLine .. lastWord
end
end
-- We wrapped - Create sprite from this line before the last word was added
if string.len(lastLine) > 0 then
table.insert(TEXT_SPRITE_LIST, fontToSprite(lastLine))
else
-- Blank line?
table.insert(TEXT_SPRITE_LIST, -1)
end
-- Get ready for the next line
line = ""
lastWord = word
newLine = true
end
spriteUnload(spriteTemp)
end
end
if newLine then
line = lastWord
end
if string.len(line) > 0 then
-- Create sprite from remaining text
table.insert(TEXT_SPRITE_LIST, fontToSprite(line))
end
end
function loadGameAssets(firstGame)
if not firstGame then
@ -161,10 +98,7 @@ function onInputPressed(what)
end
if what == SWITCH_START1 or what == SWITCH_START2 or what == SWITCH_BUTTON1 or what == SWITCH_BUTTON2 or what == SWITCH_BUTTON3 or what == SWITCH_BUTTON4 then
-- Save what game we're currently viewing
local cfg = io.open(CONFIG_FILE, "w")
cfg:write("GAME_SELECTED = " .. GAME_SELECTED .. "\n")
cfg:close()
saveConfig()
-- Start next game
scriptPush(GAME_LIST[GAME_SELECTED])
end
@ -228,6 +162,82 @@ function onOverlayUpdate()
end
function onShutdown()
saveConfig()
end
function saveConfig()
if GAME_COUNT > 0 then
-- Save what game we're currently viewing
local cfg = io.open(CONFIG_FILE, "w")
cfg:write("GAME_SELECTED = " .. GAME_SELECTED .. "\n")
cfg:close()
end
end
function wrapText(text, maxWidth)
local words = {}
local toWrap = ""
local line = ""
local lastLine = ""
local fragment = ""
local doBreak = false
local spriteTemp = -1
local trimBreak = utilTrim(WRAP_BREAK)
-- Break input into words
toWrap = text .. WRAP_BREAK
for w in toWrap:gmatch("%S+") do
words[#words+1] = w
end
-- Iterate over words and try to fit them in the space given
for _, word in ipairs(words) do
-- Is this an intentional break?
if word == trimBreak then
doBreak = true
else
-- Add this word to the line
line = utilTrim(line .. " " .. word)
-- Do we even have text?
if string.len(line) > 0 then
-- Is the line too long to fit now?
spriteTemp = fontToSprite(line)
if spriteGetWidth(spriteTemp) > maxWidth then
doBreak = true
fragment = word
line = lastLine
else
fragment = ""
end
spriteUnload(spriteTemp)
end
end
lastLine = line
-- Did we find a break?
if doBreak then
-- Did we get anything to print?
if string.len(line) > 0 then
table.insert(TEXT_SPRITE_LIST, fontToSprite(line))
else
-- Blank line
table.insert(TEXT_SPRITE_LIST, -1)
end
-- Reset for next line
line = fragment
fragment = ""
doBreak = false
end
end
end
-- Search for games.dat files in subdirectories
GAME_LIST = {}
GAME_COUNT = 0

View file

@ -58,6 +58,7 @@ function doBuild() {
done
TARGET="${SOURCE_DIR}/../build/${TARGET}${EXT}"
[[ -e "${TARGET}" ]] && rm "${TARGET}"
echo "Linking ${TARGET}..."
# The grep nonsense hides a warning we don't care about.
${CROSS}-${CPPCOMPILER} -o "${TARGET}" ${OFILES} ${EXTRA_OFILES} "-L${SOURCE_DIR}/../thirdparty-build/${OSNAME}/${OSARCH}/installed/lib" ${EXTRA_LD_FLAGS} 2>&1 | grep -v loslib || true

View file

@ -2148,13 +2148,18 @@ int32_t apiVideoLoad(lua_State *L) {
int32_t result = -1;
const char *name = NULL;
char *data = NULL;
char *temp = NULL;
VideoT *video = NULL;
if (n == 1) {
if (lua_isstring(L, 1)) {
name = lua_tostring(L, 1);
// Create data directory based on video path.
data = utilCreateString("%s%s", _global.conf.dataDirBase, utilGetUpToLastPathComponent((char *)name));
temp = utilGetUpToLastPathComponent((char *)name);
data = utilCreateString("%s%s", _global.conf.dataDirBase, temp);
free(temp);
temp = NULL;
utilFixPathSeparators(&data, false);
// Be sure it exists.
utilMkDirP(data, 0777);
if (!utilPathExists(data)) {

View file

@ -126,16 +126,29 @@ bool utilFileExists(char *filename) {
void utilFixPathSeparators(char **path, bool slash) {
int32_t i = 0;
int32_t j = 0;
char *work = *path;
char *temp = NULL;
// Flip path separators to whatever our OS wants
// Flip path separators to whatever our OS wants & remove repeated separators.
while (work[i] != 0) {
// Correct separator
if (work[i] == '\\' || work[i] == '/') {
work[i] = utilGetPathSeparator();
// Was the prior character a seprator?
if (j == 0) {
work[j++] = utilGetPathSeparator();
} else {
if (work[j - 1] != utilGetPathSeparator()) {
// No, accept it.
work[j++] = utilGetPathSeparator();
}
}
} else {
work[j++] = work[i];
}
i++;
}
work[j] = 0;
if (slash) {
// Does this string end with a path separator?
@ -170,7 +183,7 @@ char *utilGetFileExtension(char *filename) {
start = &filename[x + 1];
}
// Reset if we find a path separator
if (filename[x] == utilGetPathSeparator()) {
if (filename[x] == '\\' || filename[x] == '/') {
start = filename + strlen(filename);
}
}
@ -187,7 +200,7 @@ char *utilGetLastPathComponent(char *pathname) {
// Scan through name and find the last path separator
for (x=0; x<(int32_t)strlen(pathname); x++) {
if (pathname[x] == utilGetPathSeparator()) {
if (pathname[x] == '\\' || pathname[x] == '/') {
start = &pathname[x + 1];
}
}

View file

@ -160,12 +160,13 @@ int FFMS_CC _indexCallBack(int64_t current, int64_t total, void *ICPrivate) {
FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool hasAudio, VideoPlayerT *v) {
char indexName[1024];
char *indexName = NULL;
FFMS_Index *index = NULL;
FFMS_Indexer *indexer = NULL;
// Index file
snprintf(indexName, 1024, "%s%c%s.index", indexPath, utilGetPathSeparator(), utilGetLastPathComponent(filename));
indexName = utilCreateString("%s%c%s.index", indexPath, utilGetPathSeparator(), utilGetLastPathComponent(filename));
utilFixPathSeparators(&indexName, false);
index = FFMS_ReadIndex(indexName, &v->errInfo);
if (index) {
if (FFMS_IndexBelongsToFile(index, filename, &v->errInfo)) {
@ -184,6 +185,7 @@ FFMS_Index *_createIndex(char *filename, char *indexPath, bool hasVideo, bool ha
if (index == NULL) utilDie("%s", v->errInfo.Buffer);
if (FFMS_WriteIndex(indexName, index, &v->errInfo)) utilDie("%s", v->errInfo.Buffer);
}
free(indexName);
return index;
}