Merge branch 'replay-branch-name' into 'master'

Save branch name in replay folder

See merge request KartKrew/Kart!505
This commit is contained in:
James R 2022-01-18 07:50:02 +00:00
commit 97d1a415ce
3 changed files with 52 additions and 52 deletions

View file

@ -60,7 +60,7 @@ boolean nodrawers; // for comparative timing purposes
boolean noblit; // for comparative timing purposes boolean noblit; // for comparative timing purposes
tic_t demostarttime; // for comparative timing purposes tic_t demostarttime; // for comparative timing purposes
static char demoname[128]; static char demoname[MAX_WADPATH];
static UINT8 *demobuffer = NULL; static UINT8 *demobuffer = NULL;
static UINT8 *demotime_p, *demoinfo_p; static UINT8 *demotime_p, *demoinfo_p;
UINT8 *demo_p; UINT8 *demo_p;
@ -3791,7 +3791,7 @@ void G_SaveDemo(void)
demo_slug[strindex] = 0; demo_slug[strindex] = 0;
if (dash) demo_slug[strindex-1] = 0; if (dash) demo_slug[strindex-1] = 0;
writepoint = strstr(demoname, "-") + 1; writepoint = strstr(strrchr(demoname, *PATHSEP), "-") + 1;
demo_slug[128 - (writepoint - demoname) - 4] = 0; demo_slug[128 - (writepoint - demoname) - 4] = 0;
sprintf(writepoint, "%s.lmp", demo_slug); sprintf(writepoint, "%s.lmp", demo_slug);
} }
@ -3808,7 +3808,7 @@ void G_SaveDemo(void)
md5_buffer((char *)p+16, (demobuffer + length) - (p+16), p); md5_buffer((char *)p+16, (demobuffer + length) - (p+16), p);
#endif #endif
if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer)) // finally output the file. if (FIL_WriteFile(demoname, demobuffer, demo_p - demobuffer)) // finally output the file.
demo.savemode = DSM_SAVED; demo.savemode = DSM_SAVED;
free(demobuffer); free(demobuffer);
demo.recording = false; demo.recording = false;

View file

@ -2555,26 +2555,25 @@ const char *M_FileError(FILE *fp)
/** Return the number of parts of this path. /** Return the number of parts of this path.
*/ */
int M_PathParts(const char *path) int M_PathParts(const char *p)
{ {
int n; int parts = 0;
const char *p;
const char *t; if (p == NULL)
if (path == NULL)
return 0; return 0;
for (n = 0, p = path ;; ++n)
#ifdef _WIN32
if (!strncmp(&p[1], ":\\", 2))
p += 3;
#endif
while (*(p += strspn(p, PATHSEP)))
{ {
t = p; parts++;
if (( p = strchr(p, PATHSEP[0]) )) p += strcspn(p, PATHSEP);
p += strspn(p, PATHSEP);
else
{
if (*t)/* there is something after the final delimiter */
n++;
break;
}
} }
return n;
return parts;
} }
/** Check whether a path is an absolute path. /** Check whether a path is an absolute path.
@ -2592,50 +2591,43 @@ boolean M_IsPathAbsolute(const char *path)
*/ */
void M_MkdirEachUntil(const char *cpath, int start, int end, int mode) void M_MkdirEachUntil(const char *cpath, int start, int end, int mode)
{ {
char path[MAX_WADPATH]; char path[256];
char *p; char *p;
char *t; int n;
int c;
if (end > 0 && end <= start) if (end > 0 && end <= start)
return; return;
strlcpy(path, cpath, sizeof path); strlcpy(path, cpath, sizeof path);
#ifdef _WIN32 #ifdef _WIN32
if (strncmp(&path[1], ":\\", 2) == 0) if (!strncmp(&path[1], ":\\", 2))
p = &path[3]; p = &path[3];
else else
#endif #endif
p = path; p = path;
if (end > 0) while (end != 0 && *(p += strspn(p, PATHSEP)))
end -= start;
for (; start > 0; --start)
{ {
p += strspn(p, PATHSEP); n = strcspn(p, PATHSEP);
if (!( p = strchr(p, PATHSEP[0]) ))
return;
}
p += strspn(p, PATHSEP);
for (;;)
{
if (end > 0 && !--end)
break;
t = p; if (start > 0)
if (( p = strchr(p, PATHSEP[0]) )) start--;
{
*p = '\0';
I_mkdir(path, mode);
*p = PATHSEP[0];
p += strspn(p, PATHSEP);
}
else else
{ {
if (*t) c = p[n];
I_mkdir(path, mode); p[n] = '\0';
break;
I_mkdir(path, mode);
p[n] = c;
} }
p += n;
if (end > 0)
end--;
} }
} }
@ -2697,4 +2689,4 @@ const char * M_Ftrim (double f)
dig[i + 1] = '\0'; dig[i + 1] = '\0';
return &dig[1];/* skip the 0 */ return &dig[1];/* skip the 0 */
} }
} }

View file

@ -3798,12 +3798,20 @@ static void P_InitGametype(void)
//@TODO I'd like to fix dedis crashing when recording replays for the future too... //@TODO I'd like to fix dedis crashing when recording replays for the future too...
if (!demo.playback && multiplayer && !dedicated) if (!demo.playback && multiplayer && !dedicated)
{ {
static char buf[256]; char buf[MAX_WADPATH];
char *path; char ver[128];
sprintf(buf, "media"PATHSEP"replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); int parts;
path = va("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"online", srb2home); #ifdef DEVELOP
M_MkdirEach(path, M_PathParts(path) - 4, 0755); sprintf(ver, "%s-%s", compbranch, comprevision);
#else
strcpy(ver, VERSIONSTRING);
#endif
sprintf(buf, "%s"PATHSEP"media"PATHSEP"replay"PATHSEP"online"PATHSEP"%s"PATHSEP"%d-%s",
srb2home, ver, (int) (time(NULL)), G_BuildMapName(gamemap));
parts = M_PathParts(buf);
M_MkdirEachUntil(buf, parts - 5, parts - 1, 0755);
G_RecordDemo(buf); G_RecordDemo(buf);
} }