Skip to content

Commit

Permalink
Merge branch 'master' into screenshot-enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
walkero-gr committed Apr 20, 2023
2 parents 4d62d58 + 1882957 commit 42fefcf
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 115 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
## iGame VERSION_TAG - [RELEASE_DATE]
### Fixed
- The custom screenshot sizes were wrongly saved. This is now fixed (#190)
- Fixed a duplication in slave names after the execution of a second scan in the same list, introduced in v2.3.0
- Fixed a crash on systems that use AutoUpdateWB patch. **HUGE THANKS to mfilos** for his testing, feedback and support up to late at nights
- Fixed an error on status text after launching a game that showed total of zero games, introduced in v2.3.0
- Refactored the Slave tooltype parsing on launching to fix a memory hit and potential crashes

### Changed
- Added some spaces left and right of the screenshot. This helps to resize the sidebar as needed keeping the screenshot centred
- Now, only the screenshot part of the GUI is updated on item selection and not the whole right side. This makes the GUI refresh faster on slow computers
- If the screenshot is toggled (show/hide) in the settings window the GUI is updated without the need of restarting iGame
- Now iGame doesn't fail to start even if any of the guigfx.library, render.library or Guigfx.mcc is missing. It falls back using the datatypes and the "No GuiGfx" checkbox is blocked in the settings
- With v2.3.0 WHDLoad games that have different names on .info file against the slave file was not starting. I changed the way the necessary info file is discovered to be closer to what v2.2.1 was doing and now it works fine

## iGame 2.3.1 - [2023-04-14]
### Fixed
Expand Down
78 changes: 73 additions & 5 deletions src/fsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define iGame_NUMBERS
#include "iGame_strings.h"
Expand Down Expand Up @@ -277,15 +278,13 @@ void slavesListLoadFromCSV(char *filename)
void slavesListSaveToCSV(const char *filename)
{
char csvFilename[32];
FILE *fpgames;

const char* saving_message = (const char*)GetMBString(MSG_SavingGamelist);
set(app->TX_Status, MUIA_Text_Contents, saving_message);

strcpy(csvFilename, (CONST_STRPTR)filename);
strcat(csvFilename, ".csv");

fpgames = fopen(csvFilename, "w");
FILE *fpgames = fopen(csvFilename, "w");
if (!fpgames)
{
msg_box((const char*)GetMBString(MSG_FailedOpeningGameslist));
Expand All @@ -308,8 +307,6 @@ void slavesListSaveToCSV(const char *filename)
}

fclose(fpgames);

status_show_total();
}

/*
Expand Down Expand Up @@ -573,3 +570,74 @@ void setIconTooltypes(char *path, char *tooltypes)
}
}
}

/*
* Check if the needed slave file is set in .info tooltypes
* The infoFile needs to be the full file path without .info at the end
*/
BOOL checkSlaveInTooltypes(char *infoFile, char *slaveName)
{
struct DiskObject *diskObj = GetDiskObjectNew(infoFile);
if(diskObj)
{
if (MatchToolValue(FindToolType(diskObj->do_ToolTypes, "SLAVE"), slaveName))
{
FreeDiskObject(diskObj);
return TRUE;
}
FreeDiskObject(diskObj);
}
return FALSE;
}

/*
* Prepare the exec command based on icon tooltypes
* The infoFile needs to be the full file path without .info at the end
*/
void prepareWHDExecution(char *infoFile, char *result)
{
char *tooltypes = AllocVec(sizeof(char) * 1024, MEMF_CLEAR);
getIconTooltypes(infoFile, tooltypes);

char *buf = AllocVec(sizeof(char) * MAX_TOOLTYPE_SIZE, MEMF_CLEAR);
char **table = my_split(tooltypes, "\n");
strcpy(result, "whdload");
for (table; (buf = *table); ++table) // cppcheck-suppress redundantInitialization
{
if (buf[0] == ' ') continue;
if (buf[0] == '(') continue;
if (buf[0] == '*') continue;
if (buf[0] == ';') continue;
if (buf[0] == '\0') continue;
if (buf[0] == -69) continue; // »
if (buf[0] == -85) continue; // «
if (buf[0] == 34) continue; // \"
if (buf[0] == '.') continue;
if (buf[0] == '=') continue;
if (buf[0] == '#') continue;
if (buf[0] == '!') continue;

char** tmpTbl = my_split(buf, "=");
if (tmpTbl[1] != NULL)
{
if (tmpTbl[1][0] == '$')
{
sprintf(buf, "%s=%d", tmpTbl[0], hex2dec((char *)tmpTbl[1]));
}
else if (isNumeric(tmpTbl[1]))
{
sprintf(buf, "%s=%s", tmpTbl[0], tmpTbl[1]);
}
else
{
sprintf(buf, "%s=\"%s\"", tmpTbl[0], tmpTbl[1]);
}
}

strcat(result, " ");
strcat(result, buf);
}

FreeVec(buf);
FreeVec(tooltypes);
}
2 changes: 2 additions & 0 deletions src/fsfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ void get_path(char *, char *);
BOOL isPathFolder(char *);
void getIconTooltypes(char *, char *);
void setIconTooltypes(char *, char *);
BOOL checkSlaveInTooltypes(char *, char *);
void prepareWHDExecution(char *, char *);

#endif
133 changes: 28 additions & 105 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ extern struct Library *IconBase;
extern char* executable_name;

/* global variables */
int total_games;
int no_of_genres;
char fname[255];
BOOL sidepanelChanged = FALSE; // This is temporary until settings are revamped

/* function definitions */
static int hex2dec(char *);
static void showSlavesList(void);
static LONG xget(Object *, ULONG);

Expand All @@ -82,14 +80,6 @@ void setStatusText(char *text)
set(app->TX_Status, MUIA_Text_Contents, text);
}

void status_show_total(void)
{
char helper[200];
set(app->LV_GamesList, MUIA_List_Quiet, FALSE);
sprintf(helper, (const char*)GetMBString(MSG_TotalNumberOfGames), total_games);
set(app->TX_Status, MUIA_Text_Contents, helper);
}

static void apply_settings()
{
if (current_settings == NULL)
Expand Down Expand Up @@ -435,77 +425,6 @@ void filter_change(void)
showSlavesList();
}

static void prepareWHDExecution(slavesList *node, char *result)
{
int bufSize = sizeof(char) * MAX_PATH_SIZE;
char *buf = AllocVec(bufSize, MEMF_CLEAR);

snprintf(buf, bufSize, "%s", substring(node->path, 0, -6));
struct DiskObject *diskObj = GetDiskObjectNew(buf);
if (diskObj)
{
char to_check[256];
sprintf(result, "whdload ");

for (STRPTR *tool_types = diskObj->do_ToolTypes; (buf = *tool_types); ++tool_types)
{
if (!strncmp(buf, "*** DON'T EDIT", 14) || !strncmp(buf, "IM", 2)) continue;
if (buf[0] == ' ') continue;
if (buf[0] == '(') continue;
if (buf[0] == '*') continue;
if (buf[0] == ';') continue;
if (buf[0] == '\0') continue;
if (buf[0] == -69) continue; // »
if (buf[0] == -85) continue; // «
if (buf[0] == '.') continue;
if (buf[0] == '=') continue;
if (buf[0] == '#') continue;
if (buf[0] == '!') continue;

/* Add quotes to Execute.... ToolTypes for WHDLoad compatibility */
if (!strncmp(buf, "Execute", 7))
{
char** temp_tbl = my_split((char *)buf, "=");
if (temp_tbl == NULL) continue;
if (temp_tbl[1] != NULL)
{
sprintf(buf,"%s=\"%s\"", temp_tbl[0],temp_tbl[1]);
}

free(temp_tbl);
}

/* Must check here for numerical values */
/* Those (starting with $ should be transformed to dec from hex) */
char** temp_tbl = my_split((char *)buf, "=");
if (temp_tbl == NULL
|| temp_tbl[0] == NULL
|| !strcmp((char *)temp_tbl[0], " ")
|| !strcmp((char *)temp_tbl[0], ""))
continue;

if (temp_tbl[1] != NULL)
{
sprintf(to_check, "%s", temp_tbl[1]);
if (to_check[0] == '$')
{
const int dec_rep = hex2dec(to_check);
sprintf(buf, "%s=%d", temp_tbl[0], dec_rep);
}
}

free(temp_tbl);

strcat(result, " ");
strcat(result, buf);
}

FreeDiskObject(diskObj);
}

FreeVec(buf);
}

static BOOL createRunGameScript(slavesList *node)
{
int bufSize = sizeof(char) * MAX_PATH_SIZE;
Expand Down Expand Up @@ -543,45 +462,50 @@ static void launchSlave(slavesList *node)

const BPTR oldLock = CurrentDir(pathLock);

// Get the slave filename and replace extension
getNameFromPath(node->path, buf, bufSize);
snprintf(buf, bufSize, "%s.info", substring(buf, 0, -6));

if (Examine(pathLock, FIblock))
{
char *infoPath = AllocVec(bufSize, MEMF_CLEAR);
while (ExNext(pathLock, FIblock))
{
if (
(FIblock->fib_DirEntryType < 0) &&
(strcasestr(FIblock->fib_FileName, ".info")) &&
!strncmp(FIblock->fib_FileName, buf, sizeof(FIblock->fib_FileName))
(strcasestr(FIblock->fib_FileName, ".info"))
) {
int execSize = sizeof(char) * MAX_EXEC_SIZE;
char *exec = AllocVec(bufSize, MEMF_CLEAR);
prepareWHDExecution(node, exec);
getFullPath(FIblock->fib_FileName, infoPath);
snprintf(infoPath, bufSize, "%s", substring(infoPath, 0, -5));

// Get the slave filename
getNameFromPath(node->path, buf, bufSize);
if (checkSlaveInTooltypes(infoPath, buf))
{
int execSize = sizeof(char) * MAX_EXEC_SIZE;
char *exec = AllocVec(execSize, MEMF_CLEAR);
prepareWHDExecution(infoPath, exec);

// Update statistics info
node->last_played = 1;
node->times_played++;
// Update statistics info
node->last_played = 1;
node->times_played++;

// Save stats
if (!current_settings->save_stats_on_exit)
save_list(0);
// Save stats
if (!current_settings->save_stats_on_exit)
save_list(0);

int success = Execute(exec, 0, 0);
if (success == 0)
msg_box((const char*)GetMBString(MSG_ErrorExecutingWhdload));
int success = Execute(exec, 0, 0);
if (success == 0)
msg_box((const char*)GetMBString(MSG_ErrorExecutingWhdload));

FreeVec(exec);
FreeVec(exec);
break;
}
}
}

FreeVec(infoPath);
FreeVec(FIblock);
}

UnLock(pathLock);
CurrentDir(oldLock);
UnLock(oldLock);
}

FreeVec(buf);
Expand Down Expand Up @@ -771,7 +695,7 @@ static void showSlavesList(void)
}
set(app->LV_GamesList, MUIA_List_Quiet, FALSE);

sprintf(buf, GetMBString(MSG_TotalNumberOfGames), cnt);
sprintf(buf, (const char *)GetMBString(MSG_TotalNumberOfGames), cnt);
setStatusText(buf);
free(buf);
}
Expand Down Expand Up @@ -892,8 +816,6 @@ static BOOL examineFolder(char *path)
{
// Generate title and add in the list
generateItemName(existingNode->path, existingNode->title, sizeof(existingNode->title));

slavesListCountInstancesByTitle(existingNode);
}
}
}
Expand All @@ -914,6 +836,7 @@ void scan_repositories(void)
if (repos)
{
set(app->WI_MainWindow, MUIA_Window_Sleep, TRUE);

for (item_repos = repos; item_repos != NULL; item_repos = item_repos->next)
{
if(check_path_exists(item_repos->repo))
Expand Down Expand Up @@ -1351,7 +1274,7 @@ void open_list(void)
}

//function to return the dec eq of a hex no.
static int hex2dec(char* hexin)
int hex2dec(char *hexin)
{
unsigned int dec;
//lose the first $ character
Expand Down
2 changes: 1 addition & 1 deletion src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
#define _FUNCS_H

void msg_box(const char *);
void status_show_total(void);
void game_click(void);
void joystick_input(ULONG);
void app_stop(void);
void save_list(const int);
ULONG get_wb_version(void);
void scan_repositories(void);
void open_list(void);
int hex2dec(char *);
void save_list_as(void);
void game_delete(void);
void filter_change(void);
Expand Down
7 changes: 3 additions & 4 deletions src/slavesList.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ static BOOL slavesListRemoveHead(void) {

if (isListEmpty(slavesListHead)) {
return FALSE;
} else {
slavesList *nextPtr = slavesListHead->next;
free(slavesListHead);
slavesListHead = nextPtr;
}

slavesList *nextPtr = slavesListHead->next;
free(slavesListHead);
slavesListHead = nextPtr;
return TRUE;
}

Expand Down
Loading

0 comments on commit 42fefcf

Please sign in to comment.