]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Check if flash rom image is compressed before opening it as plain read-write file.
authorToni Wilen <twilen@winuae.net>
Wed, 21 Jan 2015 16:05:18 +0000 (18:05 +0200)
committerToni Wilen <twilen@winuae.net>
Wed, 21 Jan 2015 16:05:18 +0000 (18:05 +0200)
cpuboard.cpp

index e7fe8d57183707c44723beaf3d4822e4d8656c02..b7857919a533bafc36196437350775183b5b6a51 100644 (file)
@@ -1733,22 +1733,39 @@ static struct zfile *flashfile_open(const TCHAR *name)
 {
        struct zfile *f;
        TCHAR path[MAX_DPATH];
+       bool rw = true;
 
        if (!name[0])
                return NULL;
-       f = zfile_fopen(name, _T("rb+"), ZFD_NONE);
+       f = zfile_fopen(name, _T("rb"), ZFD_NORMAL);
+       if (f) {
+               if (zfile_iscompressed(f)) {
+                       rw = false;
+               } else {
+                       zfile_fclose(f);
+                       f = NULL;
+               }
+       }
        if (!f) {
-               f = zfile_fopen(name, _T("rb"), ZFD_NORMAL);
+               rw = true;
+               f = zfile_fopen(name, _T("rb+"), ZFD_NONE);
                if (!f) {
-                       fetch_rompath(path, sizeof path / sizeof(TCHAR));
-                       _tcscat(path, name);
-                       f = zfile_fopen(path, _T("rb+"), ZFD_NONE);
-                       if (!f)
-                               f = zfile_fopen(path, _T("rb"), ZFD_NORMAL);
+                       rw = false;
+                       f = zfile_fopen(name, _T("rb"), ZFD_NORMAL);
+                       if (!f) {
+                               fetch_rompath(path, sizeof path / sizeof(TCHAR));
+                               _tcscat(path, name);
+                               rw = true;
+                               f = zfile_fopen(path, _T("rb+"), ZFD_NONE);
+                               if (!f) {
+                                       rw = false;
+                                       f = zfile_fopen(path, _T("rb"), ZFD_NORMAL);
+                               }
+                       }
                }
        }
        if (f)
-               write_log(_T("Accelerator board flash file '%s' loaded.\n"), name);
+               write_log(_T("Accelerator board flash file '%s' loaded, %s.\n"), name, rw ? _T("RW") : _T("RO"));
        return f;
 }