Skip to content

Commit

Permalink
On Windows, the URLs were terminated with the wrong direction slash.
Browse files Browse the repository at this point in the history
  • Loading branch information
mywave82 committed Dec 21, 2024
1 parent bb60fcd commit 97e8e1e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
12 changes: 6 additions & 6 deletions filesel/modland.com/modland-com-cachedir.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,17 @@ static void modland_com_cachedir_Save (const struct DevInterfaceAPI_t *API, int
free (modland_com.cacheconfig);
switch (selected)
{
case 0: modland_com.cacheconfig = modland_com_strdup_slash ("$OCPDATAHOME/modland.com/"); break;
case 1: modland_com.cacheconfig = modland_com_strdup_slash ("$HOME/modland.com/"); break;
case 2: modland_com.cacheconfig = modland_com_strdup_slash ("$OCPDATA/modland.com/"); break;
case 3: modland_com.cacheconfig = modland_com_strdup_slash ("$TEMP/modland.com/"); break;
case 0: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$OCPDATAHOME/modland.com/"); break;
case 1: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$HOME/modland.com/"); break;
case 2: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$OCPDATA/modland.com/"); break;
case 3: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$TEMP/modland.com/"); break;

default:
case 4:
{
char *t = modland_com.cacheconfigcustom;
modland_com.cacheconfig = modland_com_strdup_slash (t);
modland_com.cacheconfigcustom = modland_com_strdup_slash (t);
modland_com.cacheconfig = modland_com_strdup_slash_filesystem (t);
modland_com.cacheconfigcustom = modland_com_strdup_slash_filesystem (t);
free (t);

free (*custom_modland_com);
Expand Down
6 changes: 3 additions & 3 deletions filesel/modland.com/modland-com-mirrors.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ static void modland_com_mirror_Save (const struct DevInterfaceAPI_t *API, int se
if (selected < NUM_MIRRORS)
{
free (modland_com.mirror);
modland_com.mirror = modland_com_strdup_slash (modland_com_official_mirror[selected]);
modland_com.mirror = modland_com_strdup_slash_url (modland_com_official_mirror[selected]);
} else {
char *t = modland_com.mirrorcustom;
free (modland_com.mirror);
modland_com.mirror = modland_com_strdup_slash (t);
modland_com.mirrorcustom = modland_com_strdup_slash (t);
modland_com.mirror = modland_com_strdup_slash_url (t);
modland_com.mirrorcustom = modland_com_strdup_slash_url (t);
free (t);
}

Expand Down
53 changes: 30 additions & 23 deletions filesel/modland.com/modland-com.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,44 +505,51 @@ static int modland_com_add_data_line (struct modland_com_initialize_t *s, const
return modland_com_add_data_fileentry (s, dir, last + 1, filesize);
}

static char *modland_com_strdup_slash(const char *src)
static char *modland_com_strdup_slash_common(const char *src, char slash)
{
char *retval;
char *e;
size_t len;

if (!src)
{
fprintf (stderr, "modland_com_strdup_slash(src): src is NULL\n");
fprintf (stderr, "modland_com_strdup_slash_common(src): src is NULL\n");
return 0;
}
e = strrchr (src,
#ifdef _WIN32
'\\'
#else
'/'
#endif
);

if (e && e[1])
len = strlen (src);
if (len)
{
e = 0;
if ( ( src[ len - 1 ] == '\\' ) || ( src[ len - 1] == '/' ) )
{
len--;
}
}
len = strlen(src) + !e + 1;
retval = malloc (len);

retval = malloc (len + 2);
if (!retval)
{
fprintf (stderr, "modland_com_strdup_slash(): malloc() failed\n");
fprintf (stderr, "modland_com_strdup_slash_common(): malloc() failed\n");
return 0;
}
snprintf (retval, len, "%s%s", src, !e ?

snprintf (retval, len + 2, "%.*s%c", (int)len, src, slash);

return retval;
}

static char *modland_com_strdup_slash_url (const char *src)
{
return modland_com_strdup_slash_common (src, '/');
}

static char *modland_com_strdup_slash_filesystem (const char *src)
{
#ifdef _WIN32
"\\"
return modland_com_strdup_slash_common (src, '\\');
#else
"/"
return modland_com_strdup_slash_common (src, '/');
#endif
: "");
return retval;
}

#include "modland-com-cachedir.c"
#include "modland-com-filehandle.c"
#include "modland-com-file.c"
Expand Down Expand Up @@ -628,14 +635,14 @@ static int modland_com_init (struct PluginInitAPI_t *API)

{
const char *temp = API->configAPI->GetProfileString ("modland.com", "mirror", "https://modland.com/");
modland_com.mirror = modland_com_strdup_slash (temp);
modland_com.mirror = modland_com_strdup_slash_url (temp);
if (!modland_com.mirror)
{
return errAllocMem;
}

temp = API->configAPI->GetProfileString ("modland.com", "mirrorcustom", modland_com.mirror);
modland_com.mirrorcustom = modland_com_strdup_slash (temp);
modland_com.mirrorcustom = modland_com_strdup_slash_url (temp);
if (!modland_com.mirrorcustom)
{
return errAllocMem;
Expand Down

0 comments on commit 97e8e1e

Please sign in to comment.