From 785908e55299f4a17b943eb4e81fc221d4782fa4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 31 May 2016 18:45:30 -0700 Subject: [PATCH 1/2] Write out correct bytes in extract file. Oops, this was always aligning to 4KB. --- Windows/MainWindowMenu.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index c70e7f72de..3a6de2fc42 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -842,9 +842,11 @@ namespace MainWindow { FILE *fp = File::OpenCFile(fn, "wb"); u32 handle = pspFileSystem.OpenFile(filename, FILEACCESS_READ, ""); u8 buffer[4096]; - while (pspFileSystem.ReadFile(handle, buffer, sizeof(buffer)) > 0) { - fwrite(buffer, sizeof(buffer), 1, fp); - } + size_t bytes; + do { + bytes = pspFileSystem.ReadFile(handle, buffer, sizeof(buffer)); + fwrite(buffer, 1, bytes, fp); + } while (bytes == sizeof(buffer)); pspFileSystem.CloseFile(handle); fclose(fp); } From 4826405c26280886ce75f9475a9897250451e910 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 4 Jun 2016 18:03:58 -0700 Subject: [PATCH 2/2] File: Retry open when a sharing violation is hit. Some editors will lock the file while it's open, and it is convenient if you can still have things work when that happens. --- Core/FileSystems/DirectoryFileSystem.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 03a6385190..8321d83bbe 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -220,6 +220,17 @@ bool DirectoryFileHandle::Open(std::string &basePath, std::string &fileName, Fil bool success = hFile != INVALID_HANDLE_VALUE; if (!success) { DWORD w32err = GetLastError(); + + if (w32err == ERROR_SHARING_VIOLATION) { + // Sometimes, the file is locked for write, let's try again. + sharemode |= FILE_SHARE_WRITE; + hFile = CreateFile(ConvertUTF8ToWString(fullName).c_str(), desired, sharemode, 0, openmode, 0, 0); + success = hFile != INVALID_HANDLE_VALUE; + if (!success) { + w32err = GetLastError(); + } + } + if (w32err == ERROR_DISK_FULL || w32err == ERROR_NOT_ENOUGH_QUOTA) { // This is returned when the disk is full. I18NCategory *err = GetI18NCategory("Error");