Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <malloc.h>
#include <windows.h>
struct multifile_fentry
{
char name[256];
UINT32 len, off;
};
class multifile_save
{
protected:
struct multifile_fentry *dic;
UINT32 anz;
FILE *dat;
multifile_save(multifile_save &x) {}
multifile_save &operator=(multifile_save &x) { return *this; }
public:
multifile_save()
{
dat = NULL;
dic = NULL;
anz = 0;
}
~multifile_save()
{
close();
}
int open(const char *destfile)
{
dic = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * 0);
anz = 0;
if(dic == NULL)
return 1;
dat = fopen(destfile, "wb");
if(dat == NULL)
{
free(dic);
return 2;
}
return 0;
}
void close()
{
fwrite((void *)dic, sizeof(multifile_fentry), anz, dat);
fwrite((void *)anz, 4, 1, dat);
fclose(dat);
free(dic);
dic = NULL;
dat = NULL;
anz = 0;
}
int addfromfile(const char *filename, const char *archivename)
{
FILE *readfile;
UINT32 len;
char buf[1024];
if(strlen(archivename) > 255)
return 1;
readfile = fopen(filename, "rb");
if(readfile == NULL)
return 2;
if((anz % 20) == 0)
{
struct multifile_fentry *dic2;
UINT32 j;
dic2 = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * (anz + 20));
if(dic2 == NULL)
{
fclose(readfile);
return 3;
}
for(j = 0; j < anz; j++)
{
dic2[j].len = dic[j].len;
dic2[j].off = dic[j].off;
strcpy(dic2[j].name, dic[j].name);
}
free(dic);
dic = dic2;
}
dic[anz].off = ftell(dat);
len = filelength(fileno(readfile));
dic[anz].len = len;
strcpy(dic[anz].name, archivename);
anz++;
while(len > 1024)
{
fread(buf, 1, 1024, readfile);
fwrite(buf, 1, 1024, dat);
len -= 1024;
}
fread(buf, 1, len, readfile);
fwrite(buf, 1, len, dat);
fclose(readfile);
return 0;
}
int addbytes(const char *bytes, UINT32 bytelen, const char *archivename)
{
if(strlen(archivename) > 255)
return 1;
if((anz % 20) == 0)
{
struct multifile_fentry *dic2;
UINT32 j;
dic2 = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * (anz + 20));
if(dic2 == NULL)
return 3;
for(j = 0; j < anz; j++)
{
dic2[j].len = dic[j].len;
dic2[j].off = dic[j].off;
strcpy(dic2[j].name, dic[j].name);
}
free(dic);
dic = dic2;
}
dic[anz].off = ftell(dat);
dic[anz].len = bytelen;
strcpy(dic[anz].name, archivename);
anz++;
fwrite(bytes, 1, bytelen, dat);
return 0;
}
};
class multifile_load
{
protected:
struct multifile_fentry *dic;
UINT32 anz;
FILE *dat;
multifile_load(multifile_load &x) {}
multifile_load &operator=(multifile_load &x) { return *this; }
public:
multifile_load()
{
dat = NULL;
dic = NULL;
anz = 0;
}
~multifile_load()
{
close();
}
int open(const char *sourcefile)
{
dat = fopen(sourcefile, "rb");
if(dat == NULL)
return 1;
fseek(dat, -4, SEEK_END);
fread((void *)anz, 4, 1, dat);
dic = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * anz);
if(dic == NULL)
{
fclose(dat);
return 2;
}
fseek(dat, -4 - (sizeof(multifile_fentry) * anz), SEEK_END);
fread((void *)dic, sizeof(multifile_fentry), anz, dat);
return 0;
}
void close()
{
fclose(dat);
free(dic);
dic = NULL;
dat = NULL;
anz = 0;
}
UINT32 getlength(const char *archivename)
{
UINT32 i;
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return -1;
return dic[i].len;
}
int readtofile(const char *filename, const char *archivename)
{
FILE *writefile;
UINT32 len, i;
char buf[1024];
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return 1;
writefile = fopen(filename, "wb");
if(writefile == NULL)
return 2;
fseek(dat, dic[i].off, SEEK_SET);
len = dic[i].len;
while(len > 1024)
{
fread(buf, 1, 1024, dat);
fwrite(buf, 1, 1024, writefile);
len -= 1024;
}
fread(buf, 1, len, dat);
fwrite(buf, 1, len, writefile);
fclose(writefile);
return 0;
}
int readbytes(char *bytes, UINT32 maxbytelen, const char *archivename)
{
UINT32 i;
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return 1;
if(dic[i].len < maxbytelen)
maxbytelen = dic[i].len;
fread(bytes, 1, maxbytelen, dat);
return 0;
}
};
int main()
{
return 0;
}
multifile_save speicherer;
speicherer.open("beide.xyz");
speicherer.addfromfile("a.jpg", "a.jpg");
speicherer.addfromfile("b.bmp", "b.bmp");
speicherer.close();
multifile_load leser;
leser.open("Beide.xyz");
leser.readtofile("a.jpg", "a.jpg");
leser.close();
fwrite((void *)anz, 4, 1, dat);
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <malloc.h>
#include <windows.h>
struct multifile_fentry
{
char name[256];
UINT32 len, off;
};
class multifile_save
{
protected:
struct multifile_fentry *dic;
UINT32 anz;
FILE *dat;
multifile_save(multifile_save &x) {}
multifile_save &operator=(multifile_save &x) { return *this; }
public:
multifile_save()
{
dat = NULL;
dic = NULL;
anz = 0;
}
~multifile_save()
{
close();
}
int open(const char *destfile)
{
dic = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * 0);
anz = 0;
if(dic == NULL)
return 1;
dat = fopen(destfile, "wb");
if(dat == NULL)
{
free(dic);
return 2;
}
return 0;
}
void close()
{
fwrite((void *)dic, sizeof(multifile_fentry), anz, dat);
fwrite((void *)anz, 4, 1, dat);
fclose(dat);
free(dic);
dic = NULL;
dat = NULL;
anz = 0;
}
int addfromfile(const char *filename, const char *archivename)
{
FILE *readfile;
UINT32 len;
char buf[1024];
if(strlen(archivename) > 255)
return 1;
readfile = fopen(filename, "rb");
if(readfile == NULL)
return 2;
if((anz % 20) == 0)
{
struct multifile_fentry *dic2;
UINT32 j;
dic2 = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * (anz + 20));
if(dic2 == NULL)
{
fclose(readfile);
return 3;
}
for(j = 0; j < anz; j++)
{
dic2[j].len = dic[j].len;
dic2[j].off = dic[j].off;
strcpy(dic2[j].name, dic[j].name);
}
free(dic);
dic = dic2;
}
dic[anz].off = ftell(dat);
len = filelength(fileno(readfile));
dic[anz].len = len;
strcpy(dic[anz].name, archivename);
anz++;
while(len > 1024)
{
fread(buf, 1, 1024, readfile);
fwrite(buf, 1, 1024, dat);
len -= 1024;
}
fread(buf, 1, len, readfile);
fwrite(buf, 1, len, dat);
fclose(readfile);
return 0;
}
int addbytes(const char *bytes, UINT32 bytelen, const char *archivename)
{
if(strlen(archivename) > 255)
return 1;
if((anz % 20) == 0)
{
struct multifile_fentry *dic2;
UINT32 j;
dic2 = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * (anz + 20));
if(dic2 == NULL)
return 3;
for(j = 0; j < anz; j++)
{
dic2[j].len = dic[j].len;
dic2[j].off = dic[j].off;
strcpy(dic2[j].name, dic[j].name);
}
free(dic);
dic = dic2;
}
dic[anz].off = ftell(dat);
dic[anz].len = bytelen;
strcpy(dic[anz].name, archivename);
anz++;
fwrite(bytes, 1, bytelen, dat);
return 0;
}
};
class multifile_load
{
protected:
struct multifile_fentry *dic;
UINT32 anz;
FILE *dat;
multifile_load(multifile_load &x) {}
multifile_load &operator=(multifile_load &x) { return *this; }
public:
multifile_load()
{
dat = NULL;
dic = NULL;
anz = 0;
}
~multifile_load()
{
close();
}
int open(const char *sourcefile)
{
dat = fopen(sourcefile, "rb");
if(dat == NULL)
return 1;
fseek(dat, -4, SEEK_END);
fread((void *)anz, 4, 1, dat);
dic = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * anz);
if(dic == NULL)
{
fclose(dat);
return 2;
}
fseek(dat, -4 - (sizeof(multifile_fentry) * anz), SEEK_END);
fread((void *)dic, sizeof(multifile_fentry), anz, dat);
return 0;
}
void close()
{
fclose(dat);
free(dic);
dic = NULL;
dat = NULL;
anz = 0;
}
UINT32 getlength(const char *archivename)
{
UINT32 i;
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return -1;
return dic[i].len;
}
int readtofile(const char *filename, const char *archivename)
{
FILE *writefile;
UINT32 len, i;
char buf[1024];
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return 1;
writefile = fopen(filename, "wb");
if(writefile == NULL)
return 2;
fseek(dat, dic[i].off, SEEK_SET);
len = dic[i].len;
while(len > 1024)
{
fread(buf, 1, 1024, dat);
fwrite(buf, 1, 1024, writefile);
len -= 1024;
}
fread(buf, 1, len, dat);
fwrite(buf, 1, len, writefile);
fclose(writefile);
return 0;
}
int readbytes(char *bytes, UINT32 maxbytelen, const char *archivename)
{
UINT32 i;
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return 1;
if(dic[i].len < maxbytelen)
maxbytelen = dic[i].len;
fread(bytes, 1, maxbytelen, dat);
return 0;
}
};
int main()
{
multifile_save speicherer;
speicherer.open("beide.xyz");
speicherer.addfromfile("a.jpg", "a");
speicherer.addfromfile("b.png", "b");
speicherer.close();
return 0;
}
Das ist klar, da close() spätestens im Destruktor automatisch aufgerufen wird.PS Auch wenn ich speicher.close() wegglasse kommt die gleiche debugger meldung
fwrite(&anz, sizeof(anz), 1, dat);
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <malloc.h>
#include <windows.h>
struct multifile_fentry
{
char name[256];
UINT32 len, off;
};
class multifile_save
{
protected:
struct multifile_fentry *dic;
UINT32 anz;
FILE *dat;
multifile_save(multifile_save &x) {}
multifile_save &operator=(multifile_save &x) { return *this; }
public:
multifile_save()
{
dat = NULL;
dic = NULL;
anz = 0;
}
~multifile_save()
{
close();
}
int open(const char *destfile)
{
dic = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * 0);
anz = 0;
if(dic == NULL)
return 1;
dat = fopen(destfile, "wb");
if(dat == NULL)
{
free(dic);
return 2;
}
return 0;
}
void close()
{
if(dat != NULL)
{
fwrite((void *)dic, sizeof(multifile_fentry), anz, dat);
fwrite((void *)(&anz), 4, 1, dat);
fclose(dat);
free(dic);
dic = NULL;
dat = NULL;
anz = 0;
}
}
int addfromfile(const char *filename, const char *archivename)
{
FILE *readfile;
UINT32 len;
char buf[1024];
if(strlen(archivename) > 255)
return 1;
readfile = fopen(filename, "rb");
if(readfile == NULL)
return 2;
if((anz % 20) == 0)
{
struct multifile_fentry *dic2;
UINT32 j;
dic2 = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * (anz + 20));
if(dic2 == NULL)
{
fclose(readfile);
return 3;
}
for(j = 0; j < anz; j++)
{
dic2[j].len = dic[j].len;
dic2[j].off = dic[j].off;
strcpy(dic2[j].name, dic[j].name);
}
free(dic);
dic = dic2;
}
dic[anz].off = ftell(dat);
len = filelength(fileno(readfile));
dic[anz].len = len;
strcpy(dic[anz].name, archivename);
anz++;
while(len > 1024)
{
fread(buf, 1, 1024, readfile);
fwrite(buf, 1, 1024, dat);
len -= 1024;
}
fread(buf, 1, len, readfile);
fwrite(buf, 1, len, dat);
fclose(readfile);
return 0;
}
int addbytes(const char *bytes, UINT32 bytelen, const char *archivename)
{
if(strlen(archivename) > 255)
return 1;
if((anz % 20) == 0)
{
struct multifile_fentry *dic2;
UINT32 j;
dic2 = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * (anz + 20));
if(dic2 == NULL)
return 3;
for(j = 0; j < anz; j++)
{
dic2[j].len = dic[j].len;
dic2[j].off = dic[j].off;
strcpy(dic2[j].name, dic[j].name);
}
free(dic);
dic = dic2;
}
dic[anz].off = ftell(dat);
dic[anz].len = bytelen;
strcpy(dic[anz].name, archivename);
anz++;
fwrite(bytes, 1, bytelen, dat);
return 0;
}
};
class multifile_load
{
protected:
struct multifile_fentry *dic;
UINT32 anz;
FILE *dat;
multifile_load(multifile_load &x) {}
multifile_load &operator=(multifile_load &x) { return *this; }
public:
multifile_load()
{
dat = NULL;
dic = NULL;
anz = 0;
}
~multifile_load()
{
close();
}
int open(const char *sourcefile)
{
dat = fopen(sourcefile, "rb");
if(dat == NULL)
return 1;
fseek(dat, -4, SEEK_END);
fread((void *)(&anz), 4, 1, dat);
dic = (struct multifile_fentry *)malloc(sizeof(multifile_fentry) * anz);
if(dic == NULL)
{
fclose(dat);
return 2;
}
fseek(dat, -4 - (sizeof(multifile_fentry) * anz), SEEK_END);
fread((void *)dic, sizeof(multifile_fentry), anz, dat);
return 0;
}
void close()
{
if(dat != NULL)
{
fclose(dat);
free(dic);
dic = NULL;
dat = NULL;
anz = 0;
}
}
UINT32 getlength(const char *archivename)
{
UINT32 i;
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return -1;
return dic[i].len;
}
int readtofile(const char *filename, const char *archivename)
{
FILE *writefile;
UINT32 len, i;
char buf[1024];
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return 1;
writefile = fopen(filename, "wb");
if(writefile == NULL)
return 2;
fseek(dat, dic[i].off, SEEK_SET);
len = dic[i].len;
while(len > 1024)
{
fread(buf, 1, 1024, dat);
fwrite(buf, 1, 1024, writefile);
len -= 1024;
}
fread(buf, 1, len, dat);
fwrite(buf, 1, len, writefile);
fclose(writefile);
return 0;
}
int readbytes(char *bytes, UINT32 maxbytelen, const char *archivename)
{
UINT32 i;
for(i = 0; i < anz; i++)
{
if(!strcmp(dic[i].name, archivename))
break;
}
if(i >= anz)
return 1;
if(dic[i].len < maxbytelen)
maxbytelen = dic[i].len;
fread(bytes, 1, maxbytelen, dat);
return 0;
}
};
int main()
{
return 0;
}