mirror of https://github.com/mgba-emu/mgba.git
Updater: Log to file
This commit is contained in:
parent
ac8c371219
commit
903f792731
|
@ -29,6 +29,8 @@
|
||||||
#define W_OK 02
|
#define W_OK 02
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
FILE* logfile;
|
||||||
|
|
||||||
bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
|
bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
|
||||||
char path[PATH_MAX] = {0};
|
char path[PATH_MAX] = {0};
|
||||||
struct VDirEntry* vde;
|
struct VDirEntry* vde;
|
||||||
|
@ -53,7 +55,7 @@ bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
|
||||||
}
|
}
|
||||||
switch (vde->type(vde)) {
|
switch (vde->type(vde)) {
|
||||||
case VFS_DIRECTORY:
|
case VFS_DIRECTORY:
|
||||||
printf("mkdir %s\n", fname);
|
fprintf(logfile, "mkdir %s\n", fname);
|
||||||
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
|
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +72,7 @@ bool extractArchive(struct VDir* archive, const char* root, bool prefix) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VFS_FILE:
|
case VFS_FILE:
|
||||||
printf("extract %s\n", fname);
|
fprintf(logfile, "extract %s\n", fname);
|
||||||
vfIn = archive->openFile(archive, vde->name(vde), O_RDONLY);
|
vfIn = archive->openFile(archive, vde->name(vde), O_RDONLY);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
|
vfOut = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
|
@ -111,13 +113,17 @@ int main(int argc, char* argv[]) {
|
||||||
const char* root;
|
const char* root;
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
|
|
||||||
|
mCoreConfigDirectory(bin, sizeof(bin));
|
||||||
|
strncat(bin, "/updater.log", sizeof(bin));
|
||||||
|
logfile = fopen(bin, "w");
|
||||||
|
|
||||||
mCoreConfigInit(&config, "updater");
|
mCoreConfigInit(&config, "updater");
|
||||||
if (!mCoreConfigLoad(&config)) {
|
if (!mCoreConfigLoad(&config)) {
|
||||||
puts("Failed to load config");
|
fputs("Failed to load config", logfile);
|
||||||
} else if (!mUpdateGetArchivePath(&config, updateArchive, sizeof(updateArchive)) || !(root = mUpdateGetRoot(&config))) {
|
} else if (!mUpdateGetArchivePath(&config, updateArchive, sizeof(updateArchive)) || !(root = mUpdateGetRoot(&config))) {
|
||||||
puts("No pending update found");
|
fputs("No pending update found", logfile);
|
||||||
} else if (access(root, W_OK)) {
|
} else if (access(root, W_OK)) {
|
||||||
puts("Cannot write to update path");
|
fputs("Cannot write to update path", logfile);
|
||||||
} else {
|
} else {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
char subdir[PATH_MAX];
|
char subdir[PATH_MAX];
|
||||||
|
@ -160,7 +166,7 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
off_t diff = devend - devinfo - 1;
|
off_t diff = devend - devinfo - 1;
|
||||||
memcpy(devpath, &devinfo[1], diff);
|
memcpy(devpath, &devinfo[1], diff);
|
||||||
puts(devpath);
|
fputs(devpath, logfile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int retstat;
|
int retstat;
|
||||||
|
@ -177,11 +183,11 @@ int main(int argc, char* argv[]) {
|
||||||
archive = VDirOpenArchive(updateArchive);
|
archive = VDirOpenArchive(updateArchive);
|
||||||
}
|
}
|
||||||
if (archive) {
|
if (archive) {
|
||||||
puts("Extracting update");
|
fputs("Extracting update", logfile);
|
||||||
if (extractArchive(archive, root, prefix)) {
|
if (extractArchive(archive, root, prefix)) {
|
||||||
ok = 0;
|
ok = 0;
|
||||||
} else {
|
} else {
|
||||||
puts("An error occurred");
|
fputs("An error occurred", logfile);
|
||||||
}
|
}
|
||||||
archive->close(archive);
|
archive->close(archive);
|
||||||
unlink(updateArchive);
|
unlink(updateArchive);
|
||||||
|
@ -218,10 +224,10 @@ int main(int argc, char* argv[]) {
|
||||||
close(infd);
|
close(infd);
|
||||||
}
|
}
|
||||||
if (ok == 2) {
|
if (ok == 2) {
|
||||||
puts("Cannot move update over old file");
|
fputs("Cannot move update over old file", logfile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
puts("Cannot move update over old file");
|
fputs("Cannot move update over old file", logfile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ok = 0;
|
ok = 0;
|
||||||
|
@ -232,10 +238,10 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
puts("Cannot open update archive");
|
fputs("Cannot open update archive", logfile);
|
||||||
}
|
}
|
||||||
if (ok == 0) {
|
if (ok == 0) {
|
||||||
puts("Complete");
|
fputs("Complete", logfile);
|
||||||
const char* command = mUpdateGetCommand(&config);
|
const char* command = mUpdateGetCommand(&config);
|
||||||
strlcpy(bin, command, sizeof(bin));
|
strlcpy(bin, command, sizeof(bin));
|
||||||
mUpdateDeregister(&config);
|
mUpdateDeregister(&config);
|
||||||
|
@ -260,6 +266,7 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCoreConfigDeinit(&config);
|
mCoreConfigDeinit(&config);
|
||||||
|
fclose(logfile);
|
||||||
if (ok == 0) {
|
if (ok == 0) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char qbin[PATH_MAX + 2] = {0};
|
char qbin[PATH_MAX + 2] = {0};
|
||||||
|
|
Loading…
Reference in New Issue