Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/playstore' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
flyinghead committed Aug 24, 2024
2 parents 308d9fc + 8ea1244 commit a93bd9e
Show file tree
Hide file tree
Showing 43 changed files with 1,349 additions and 340 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ jobs:
key: android-ccache-${{ github.sha }}
restore-keys: android-ccache-

- name: Bump version code
uses: chkfung/android-version-actions@v1.2.2
with:
gradlePath: shell/android-studio/flycast/build.gradle
versionCode: ${{ github.run_number }}

- name: Gradle
working-directory: shell/android-studio
run: ./gradlew assembleRelease --parallel
run: ./gradlew assembleRelease bundleRelease --parallel
env:
SENTRY_UPLOAD_URL: ${{ secrets.SENTRY_UPLOAD_URL }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}

- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -68,7 +75,9 @@ jobs:
if: github.repository == 'flyinghead/flycast' && github.event_name == 'push'

- name: Upload to S3
run: aws s3 sync shell/android-studio/flycast/build/outputs/apk/release s3://flycast-builds/android/${GITHUB_REF#refs/}-$GITHUB_SHA --acl public-read --exclude='*.json' --follow-symlinks
run: |
cp shell/android-studio/flycast/build/outputs/bundle/release/*.aab shell/android-studio/flycast/build/outputs/apk/release/
aws s3 sync shell/android-studio/flycast/build/outputs/apk/release s3://flycast-builds/android/${GITHUB_REF#refs/}-$GITHUB_SHA --acl public-read --exclude='*.json' --follow-symlinks
if: ${{ steps.aws-credentials.outputs.aws-account-id != '' }}

- name: Setup Sentry CLI
Expand Down
2 changes: 1 addition & 1 deletion core/audio/audiobackend_oboe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class OboeBackend : AudioBackend
}
recordStream->requestStart();
NOTICE_LOG(AUDIO, "Oboe recorder started. stream capacity: %d frames",
stream->getBufferCapacityInFrames());
recordStream->getBufferCapacityInFrames());

return true;
}
Expand Down
13 changes: 9 additions & 4 deletions core/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,15 +944,20 @@ void Emulator::start()
bool Emulator::checkStatus(bool wait)
{
try {
const std::lock_guard<std::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
if (threadResult.valid())
{
if (!wait)
{
auto result = threadResult.wait_for(std::chrono::seconds(0));
lock.unlock();
auto localResult = threadResult;
if (wait) {
localResult.wait();
}
else {
auto result = localResult.wait_for(std::chrono::seconds(0));
if (result == std::future_status::timeout)
return true;
}
lock.lock();
threadResult.get();
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion core/emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Emulator
Terminated,
};
State state = Uninitialized;
std::future<void> threadResult;
std::shared_future<void> threadResult;
bool resetRequested = false;
bool singleStep = false;
u64 startTime = 0;
Expand Down
3 changes: 2 additions & 1 deletion core/hw/flashrom/flashrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#include "flashrom.h"
#include "oslib/oslib.h"
#include "stdclass.h"
#include "oslib/storage.h"

bool MemChip::Load(const std::string& file)
{
FILE *f = nowide::fopen(file.c_str(), "rb");
FILE *f = hostfs::storage().openFile(file, "rb");
if (f)
{
bool rv = std::fread(data + write_protect_size, 1, size - write_protect_size, f) == size - write_protect_size;
Expand Down
4 changes: 2 additions & 2 deletions core/hw/naomi/gdcartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,18 @@ void GDCartridge::device_start(LoadProgress *progress, std::vector<u8> *digest)
u8 buffer[2048];
std::string parent = hostfs::storage().getParentPath(settings.content.path);
std::string gdrom_path = get_file_basename(settings.content.fileName) + "/" + gdrom_name;
gdrom_path = hostfs::storage().getSubPath(parent, gdrom_path);
std::unique_ptr<Disc> gdrom;
try {
gdrom_path = hostfs::storage().getSubPath(parent, gdrom_path);
gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_path + ".chd", digest));
}
catch (const FlycastException& e)
{
WARN_LOG(NAOMI, "Opening chd failed: %s", e.what());
if (gdrom_parent_name != nullptr)
{
std::string gdrom_parent_path = hostfs::storage().getSubPath(parent, std::string(gdrom_parent_name) + "/" + gdrom_name);
try {
std::string gdrom_parent_path = hostfs::storage().getSubPath(parent, std::string(gdrom_parent_name) + "/" + gdrom_name);
gdrom = std::unique_ptr<Disc>(OpenDisc(gdrom_parent_path + ".chd", digest));
} catch (const FlycastException& e) {
WARN_LOG(NAOMI, "Opening parent chd failed: %s", e.what());
Expand Down
16 changes: 11 additions & 5 deletions core/hw/naomi/naomi_cart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ void naomi_cart_LoadBios(const char *filename)
std::unique_ptr<Archive> parent_archive;
if (game->parent_name != nullptr)
{
std::string parentPath = hostfs::storage().getParentPath(filename);
parentPath = hostfs::storage().getSubPath(parentPath, game->parent_name);
parent_archive.reset(OpenArchive(parentPath));
try {
std::string parentPath = hostfs::storage().getParentPath(filename);
parentPath = hostfs::storage().getSubPath(parentPath, game->parent_name);
parent_archive.reset(OpenArchive(parentPath));
} catch (const FlycastException& e) {
}
}

const char *bios = "naomi";
Expand Down Expand Up @@ -219,8 +222,11 @@ static void loadMameRom(const std::string& path, const std::string& fileName, Lo
if (game->parent_name != nullptr)
{
std::string parentPath = hostfs::storage().getParentPath(path);
parentPath = hostfs::storage().getSubPath(parentPath, game->parent_name);
parent_archive.reset(OpenArchive(parentPath));
try {
parentPath = hostfs::storage().getSubPath(parentPath, game->parent_name);
parent_archive.reset(OpenArchive(parentPath));
} catch (const FlycastException& e) {
}
if (parent_archive != nullptr)
INFO_LOG(NAOMI, "Opened %s", game->parent_name);
else
Expand Down
14 changes: 10 additions & 4 deletions core/hw/naomi/systemsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,12 +2088,18 @@ void SystemSpCart::Init(LoadProgress *progress, std::vector<u8> *digest)
{
std::string parent = hostfs::storage().getParentPath(settings.content.path);
std::string gdrom_path = get_file_basename(settings.content.fileName) + "/" + std::string(mediaName) + ".chd";
gdrom_path = hostfs::storage().getSubPath(parent, gdrom_path);
chd = openChd(gdrom_path);
try {
gdrom_path = hostfs::storage().getSubPath(parent, gdrom_path);
chd = openChd(gdrom_path);
} catch (const FlycastException& e) {
}
if (parentName != nullptr && chd == nullptr)
{
std::string gdrom_parent_path = hostfs::storage().getSubPath(parent, std::string(parentName) + "/" + std::string(mediaName) + ".chd");
chd = openChd(gdrom_parent_path);
try {
std::string gdrom_parent_path = hostfs::storage().getSubPath(parent, std::string(parentName) + "/" + std::string(mediaName) + ".chd");
chd = openChd(gdrom_parent_path);
} catch (const FlycastException& e) {
}
}
if (chd == nullptr)
throw NaomiCartException("SystemSP: Cannot open CompactFlash file " + gdrom_path);
Expand Down
45 changes: 31 additions & 14 deletions core/nullDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ui/gui.h"
#include "oslib/oslib.h"
#include "oslib/directory.h"
#include "oslib/storage.h"
#include "debug/gdb_server.h"
#include "archive/rzip.h"
#include "ui/mainui.h"
Expand All @@ -17,6 +18,9 @@
#include "serialize.h"
#include <time.h>

static std::string lastStateFile;
static time_t lastStateTime;

struct SavestateHeader
{
void init()
Expand Down Expand Up @@ -121,6 +125,8 @@ void dc_savestate(int index, const u8 *pngData, u32 pngSize)
if (settings.network.online)
return;

lastStateFile.clear();

Serializer ser;
dc_serialize(ser);

Expand Down Expand Up @@ -189,7 +195,7 @@ void dc_loadstate(int index)
u32 total_size = 0;

std::string filename = hostfs::getSavestatePath(index, false);
FILE *f = nowide::fopen(filename.c_str(), "rb");
FILE *f = hostfs::storage().openFile(filename, "rb");
if (f == nullptr)
{
WARN_LOG(SAVESTATE, "Failed to load state - could not open %s for reading", filename.c_str());
Expand Down Expand Up @@ -278,28 +284,39 @@ void dc_loadstate(int index)
time_t dc_getStateCreationDate(int index)
{
std::string filename = hostfs::getSavestatePath(index, false);
FILE *f = nowide::fopen(filename.c_str(), "rb");
if (f == nullptr)
return 0;
SavestateHeader header;
if (std::fread(&header, sizeof(header), 1, f) != 1 || !header.isValid())
if (filename != lastStateFile)
{
std::fclose(f);
struct stat st;
if (flycast::stat(filename.c_str(), &st) == 0)
return st.st_mtime;
lastStateFile = filename;
FILE *f = hostfs::storage().openFile(filename, "rb");
if (f == nullptr)
lastStateTime = 0;
else
return 0;
{
SavestateHeader header;
if (std::fread(&header, sizeof(header), 1, f) != 1 || !header.isValid())
{
std::fclose(f);
try {
hostfs::FileInfo fileInfo = hostfs::storage().getFileInfo(filename);
lastStateTime = fileInfo.updateTime;
} catch (...) {
lastStateTime = 0;
}
}
else {
std::fclose(f);
lastStateTime = (time_t)header.creationDate;
}
}
}
std::fclose(f);
return (time_t)header.creationDate;
return lastStateTime;
}

void dc_getStateScreenshot(int index, std::vector<u8>& pngData)
{
pngData.clear();
std::string filename = hostfs::getSavestatePath(index, false);
FILE *f = nowide::fopen(filename.c_str(), "rb");
FILE *f = hostfs::storage().openFile(filename, "rb");
if (f == nullptr)
return;
SavestateHeader header;
Expand Down
17 changes: 10 additions & 7 deletions core/oslib/oslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ std::string findFlash(const std::string& prefix, const std::string& names)
name = name.replace(percent, 1, prefix);

std::string fullpath = get_readonly_data_path(name);
if (file_exists(fullpath))
if (hostfs::storage().exists(fullpath))
return fullpath;
for (const auto& path : config::ContentPath.get())
{
fullpath = path + "/" + name;
if (file_exists(fullpath))
return fullpath;
try {
fullpath = hostfs::storage().getSubPath(path, name);
if (hostfs::storage().exists(fullpath))
return fullpath;
} catch (const hostfs::StorageException& e) {
}
}

start = semicolon;
Expand All @@ -103,14 +106,14 @@ std::string getFlashSavePath(const std::string& prefix, const std::string& name)
std::string findNaomiBios(const std::string& name)
{
std::string fullpath = get_readonly_data_path(name);
if (file_exists(fullpath))
if (hostfs::storage().exists(fullpath))
return fullpath;
for (const auto& path : config::ContentPath.get())
{
try {
fullpath = hostfs::storage().getSubPath(path, name);
hostfs::storage().getFileInfo(fullpath);
return fullpath;
if (hostfs::storage().exists(fullpath))
return fullpath;
} catch (const hostfs::StorageException& e) {
}
}
Expand Down
5 changes: 5 additions & 0 deletions core/oslib/oslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ namespace hostfs

std::string getShaderCachePath(const std::string& filename);
void saveScreenshot(const std::string& name, const std::vector<u8>& data);

#ifdef __ANDROID__
void importHomeDirectory();
void exportHomeDirectory();
#endif
}

static inline void *allocAligned(size_t alignment, size_t size)
Expand Down
35 changes: 32 additions & 3 deletions core/oslib/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ CustomStorage& customStorage()
std::string getParentPath(const std::string& path) override { die("Not implemented"); }
std::string getSubPath(const std::string& reference, const std::string& relative) override { die("Not implemented"); }
FileInfo getFileInfo(const std::string& path) override { die("Not implemented"); }
void addStorage(bool isDirectory, bool writeAccess, void (*callback)(bool cancelled, std::string selectedPath)) override {
bool exists(const std::string& path) override { die("Not implemented"); }
bool addStorage(bool isDirectory, bool writeAccess, void (*callback)(bool cancelled, std::string selectedPath)) override {
die("Not implemented");
}
};
Expand Down Expand Up @@ -190,6 +191,7 @@ class StdStorage : public Storage
}
info.isDirectory = S_ISDIR(st.st_mode);
info.size = st.st_size;
info.updateTime = st.st_mtime;
#else // _WIN32
nowide::wstackstring wname;
if (wname.convert(path.c_str()))
Expand All @@ -199,6 +201,8 @@ class StdStorage : public Storage
{
info.isDirectory = (fileAttribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info.size = fileAttribs.nFileSizeLow + ((u64)fileAttribs.nFileSizeHigh << 32);
u64 t = ((u64)fileAttribs.ftLastWriteTime.dwHighDateTime << 32) | fileAttribs.ftLastWriteTime.dwLowDateTime;
info.updateTime = t / 10000000 - 11644473600LL; // 100-nano to secs minus (unix epoch - windows epoch)
}
else
{
Expand All @@ -218,6 +222,23 @@ class StdStorage : public Storage
return info;
}

bool exists(const std::string& path) override
{
#ifndef _WIN32
struct stat st;
return flycast::stat(path.c_str(), &st) == 0;
#else // _WIN32
nowide::wstackstring wname;
if (wname.convert(path.c_str()))
{
WIN32_FILE_ATTRIBUTE_DATA fileAttribs;
if (GetFileAttributesExW(wname.get(), GetFileExInfoStandard, &fileAttribs))
return true;
}
return false;
#endif
}

private:
std::vector<FileInfo> listRoots()
{
Expand Down Expand Up @@ -319,6 +340,14 @@ FileInfo AllStorage::getFileInfo(const std::string& path)
return stdStorage.getFileInfo(path);
}

bool AllStorage::exists(const std::string& path)
{
if (customStorage().isKnownPath(path))
return customStorage().exists(path);
else
return stdStorage.exists(path);
}

std::string AllStorage::getDefaultDirectory()
{
std::string directory;
Expand Down Expand Up @@ -363,9 +392,9 @@ AllStorage& storage()
return storage;
}

void addStorage(bool isDirectory, bool writeAccess, void (*callback)(bool cancelled, std::string selectedPath))
bool addStorage(bool isDirectory, bool writeAccess, void (*callback)(bool cancelled, std::string selectedPath))
{
customStorage().addStorage(isDirectory, writeAccess, callback);
return customStorage().addStorage(isDirectory, writeAccess, callback);
}

}
Loading

0 comments on commit a93bd9e

Please sign in to comment.