Fix snapshot filenames

This commit is contained in:
statmat
2004-04-27 21:28:27 +00:00
parent 90a15b7201
commit 6b19fff805
2 changed files with 1850 additions and 1840 deletions

View File

@@ -1418,31 +1418,43 @@ NEWSYM GetFreeFile
%else
mov esi,fnames+1
mov ebx,.imagefname
.next
.end1
mov al,[esi]
mov [ebx],al
inc esi
inc ebx
cmp al,0
jne .end1
.end2
dec esi
mov al,[esi]
cmp al,'.'
jne .end2
mov edx,fnames+1
.next
mov al,[edx]
mov [ebx],al
inc edx
inc ebx
cmp edx,esi
jne .next
mov esi,ebx
mov byte[esi-1],' '
mov byte[esi],'0'
mov byte[esi],' '
mov byte[esi+1],'0'
mov byte[esi+2],'0'
mov byte[esi+3],'.'
mov byte[esi+3],'0'
mov byte[esi+4],'0'
mov byte[esi+5],'.'
cmp ecx,0
jne .isbmp
mov byte[esi+4],'p'
mov byte[esi+5],'c'
mov byte[esi+6],'x'
mov byte[esi+6],'p'
mov byte[esi+7],'c'
mov byte[esi+8],'x'
jmp .doneextselect
.isbmp
mov byte[esi+4],'b'
mov byte[esi+5],'m'
mov byte[esi+6],'p'
mov byte[esi+6],'b'
mov byte[esi+7],'m'
mov byte[esi+8],'p'
.doneextselect
mov byte[esi+7],0
mov byte[esi+9],0
mov word[picnum],0
.findagain
@@ -1453,24 +1465,28 @@ NEWSYM GetFreeFile
call Close_File
inc word[picnum]
cmp word[picnum],1000
cmp word[picnum],10000
je .nofile
mov ax,[picnum]
xor edx,edx
mov bx,1000
div bx
add al,48
mov byte[esi+1],al
mov ax,dx
xor edx,edx
mov bx,100
div bx
mov cl,al
add al,48
mov byte[esi+2],al
mov ax,dx
xor edx,edx
mov bx,10
div bx
add cl,48
add al,48
add dl,48
mov byte[esi],cl
mov byte[esi+1],al
mov byte[esi+2],dl
mov byte[esi+3],al
mov byte[esi+4],dl
jmp .findagain
.nofile
mov edx,.imagefname

View File

@@ -3,6 +3,7 @@
#ifdef __WIN32__
#include <windows.h>
#include <sys/stat.h>
#ifdef __WIN32DBG__
#include <crtdbg.h>
@@ -123,12 +124,9 @@ char *generate_filename(void)
extern char fnames;
char *filename;
char *tmp = &fnames;
char *tmp2 = 0;
short i=0;
#ifdef __WIN32__
SYSTEMTIME time;
#else
struct stat buf;
#endif
#ifdef __MSDOS__
filename = (char *)malloc(14);
@@ -143,45 +141,41 @@ char *generate_filename(void)
return filename;
#endif
tmp++; // the first char is the string length
// removes the path if there is one
while (*tmp!=0) tmp++;
while ((*tmp!='/') && (tmp!=&fnames)) tmp--;
tmp++;
// allocates enough memory to store the filename
#ifdef __LINUX__
filename = (char *)malloc(strlen(tmp)+10);
#endif
#ifdef __WIN32__
filename = (char *)malloc(strlen(tmp)+25);
#endif
strcpy(filename, tmp);
tmp = filename;
while (*tmp!='.') {
if (*tmp == ' ') *tmp = '_';
tmp++;
}
#ifdef __WIN32__
/*get system time.*/
GetLocalTime(&time);
tmp = filename+strlen(filename);
while (*tmp!='.') tmp--;
/*make filename from local time*/
wsprintf(tmp," %d %02d_%02d %02d-%02d-%02d.png\0", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
#endif
#ifdef __LINUX__
tmp2 = filename;
while (tmp2<tmp) {
if (*tmp2 == ' ') *tmp2 = '_';
tmp2++;
}
#endif
/*find first unused file*/
/*Note: this results in a 1000 image limit!*/
/*Note: this results in a 9999 image limit!*/
for(i=0;i<10000;i++)
{
sprintf(tmp, "_%04d.png", i);
#ifdef __LINUX__
sprintf(tmp, "_%04d.png\0", i);
#else
sprintf(tmp, " %04d.png\0", i);
#endif
if(stat(filename, &buf)==-1)
break;
}
#endif
return filename;
}