Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the resource system respects the liveupdate.enabled flag #8189

Merged
merged 1 commit into from Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 44 additions & 8 deletions engine/liveupdate/src/liveupdate.cpp
Expand Up @@ -92,6 +92,7 @@ namespace dmLiveUpdate
DM_LU_RESULT_TO_STR(FORMAT_ERROR);
DM_LU_RESULT_TO_STR(IO_ERROR);
DM_LU_RESULT_TO_STR(INVAL);
DM_LU_RESULT_TO_STR(NOT_INITIALIZED);
DM_LU_RESULT_TO_STR(UNKNOWN);
default: break;
}
Expand All @@ -116,6 +117,7 @@ namespace dmLiveUpdate
dmResource::HFactory m_ResourceFactory; // Resource system factory
dmResourceProvider::HArchive m_LiveupdateArchive;
dmResource::HManifest m_LiveupdateArchiveManifest;
bool m_IsEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we don't set it anywhere and it's false by default


} g_LiveUpdate;

Expand Down Expand Up @@ -368,7 +370,13 @@ namespace dmLiveUpdate
return archive;
}

static bool IsLiveupdateDisabled()
static bool IsLiveupdateEnabled()
{
return g_LiveUpdate.m_IsEnabled;
}


static bool IsLiveupdateThreadDisabled()
{
if (!g_LiveUpdate.m_JobThread)
{
Expand Down Expand Up @@ -479,6 +487,9 @@ namespace dmLiveUpdate

Result StoreResourceAsync(const char* expected_digest, const uint32_t expected_digest_length, const dmResourceArchive::LiveUpdateResource* resource, void (*callback)(bool, void*), void* callback_data)
{
if (!IsLiveupdateEnabled())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: I know that we are mixing one-line conditionals with and without curly brackets, but which is the style to use in the Defold code base? I noticed that you removed curly brackets in the code you touched a bit further down?

Copy link
Contributor Author

@JCash JCash Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's depending on context.
In general, I want less "fluff" that makes it harder to read (for me)

I personally think that a scope (curly braces) isn't needed when all we do is return a value.

Assignments may be different.
And often I leave the braces if I for instance have debugged the scope using a printf or similar.

return RESULT_NOT_INITIALIZED;

if (resource->m_Data == 0x0)
{
return RESULT_MEM_ERROR;
Expand All @@ -490,7 +501,7 @@ namespace dmLiveUpdate
return RESULT_INVALID_RESOURCE;
}

if(IsLiveupdateDisabled())
if(IsLiveupdateThreadDisabled())
{
return RESULT_INVAL;
}
Expand Down Expand Up @@ -581,12 +592,15 @@ namespace dmLiveUpdate

Result StoreManifestAsync(const uint8_t* manifest_data, uint32_t manifest_len, void (*callback)(int, void*), void* callback_data)
{
if (!IsLiveupdateEnabled())
return RESULT_NOT_INITIALIZED;

if (!manifest_data || manifest_len == 0)
{
return RESULT_INVAL;
}

if(IsLiveupdateDisabled())
if(IsLiveupdateThreadDisabled())
{
return RESULT_INVAL;
}
Expand Down Expand Up @@ -689,12 +703,15 @@ namespace dmLiveUpdate

Result StoreArchiveAsync(const char* path, void (*callback)(const char*, int, void*), void* callback_data, const char* mountname, int priority, bool verify_archive)
{
if (!IsLiveupdateEnabled())
return RESULT_NOT_INITIALIZED;

if (!dmSys::Exists(path)) {
dmLogError("File does not exist: '%s'", path);
return RESULT_INVALID_RESOURCE;
}

if(IsLiveupdateDisabled())
if(IsLiveupdateThreadDisabled())
{
return RESULT_INVAL;
}
Expand Down Expand Up @@ -780,10 +797,10 @@ namespace dmLiveUpdate

Result AddMountAsync(const char* name, const char* uri, int priority, void (*callback)(const char*, const char*, int, void*), void* callback_data)
{
if(IsLiveupdateDisabled())
{
return RESULT_INVAL;
}
if (!IsLiveupdateEnabled())
return RESULT_NOT_INITIALIZED;
if(IsLiveupdateThreadDisabled())
return RESULT_NOT_INITIALIZED;

AddMountInfo* info = new AddMountInfo;
info->m_Archive = g_LiveUpdate.m_LiveupdateArchive;
Expand All @@ -799,6 +816,9 @@ namespace dmLiveUpdate

Result RemoveMountSync(const char* name)
{
if (!IsLiveupdateEnabled())
return RESULT_NOT_INITIALIZED;

dmResourceMounts::HContext mounts = g_LiveUpdate.m_ResourceMounts;
dmMutex::HMutex mutex = dmResourceMounts::GetMutex(mounts);
DM_MUTEX_SCOPED_LOCK(mutex);
Expand Down Expand Up @@ -841,6 +861,9 @@ namespace dmLiveUpdate

bool HasLiveUpdateMount()
{
if (!IsLiveupdateEnabled())
return false;

dmMutex::HMutex mutex = dmResourceMounts::GetMutex(g_LiveUpdate.m_ResourceMounts);
DM_MUTEX_SCOPED_LOCK(mutex);

Expand Down Expand Up @@ -887,6 +910,13 @@ namespace dmLiveUpdate

static dmExtension::Result Initialize(dmExtension::Params* params)
{
int32_t liveupdate_enabled = dmConfigFile::GetInt(params->m_ConfigFile, "liveupdate.enabled", 1);
if (!liveupdate_enabled)
{
dmLogError("Liveupdate disabled due to project setting %s=%d", "liveupdate.enabled", liveupdate_enabled);
return dmExtension::RESULT_OK;
}

dmResource::HFactory factory = params->m_ResourceFactory;

g_LiveUpdate.m_ResourceFactory = factory;
Expand Down Expand Up @@ -931,6 +961,9 @@ namespace dmLiveUpdate

static dmExtension::Result Finalize(dmExtension::Params* params)
{
if (!IsLiveupdateEnabled())
return dmExtension::RESULT_OK;

if (g_LiveUpdate.m_JobThread)
dmJobThread::Destroy(g_LiveUpdate.m_JobThread);
g_LiveUpdate.m_JobThread = 0;
Expand All @@ -940,6 +973,9 @@ namespace dmLiveUpdate

static dmExtension::Result Update(dmExtension::Params* params)
{
if (!IsLiveupdateEnabled())
return dmExtension::RESULT_OK;

if (!g_LiveUpdate.m_ResourceBaseArchive)
return dmExtension::RESULT_OK;

Expand Down
1 change: 1 addition & 0 deletions engine/liveupdate/src/liveupdate.h
Expand Up @@ -48,6 +48,7 @@ namespace dmLiveUpdate
RESULT_FORMAT_ERROR = -9,
RESULT_IO_ERROR = -10,
RESULT_INVAL = -11,
RESULT_NOT_INITIALIZED = -12,
RESULT_UNKNOWN = -1000,
};

Expand Down
1 change: 1 addition & 0 deletions engine/liveupdate/src/script_liveupdate.cpp
Expand Up @@ -441,6 +441,7 @@ DEPRECATE_LU_FUNCTION("store_archive", Resource_StoreArchive);
SETCONSTANT(FORMAT_ERROR);
SETCONSTANT(IO_ERROR);
SETCONSTANT(INVAL);
SETCONSTANT(NOT_INITIALIZED);
SETCONSTANT(UNKNOWN);
}

Expand Down
17 changes: 12 additions & 5 deletions engine/resource/src/resource.cpp
Expand Up @@ -299,15 +299,22 @@ HFactory NewFactory(NewFactoryParams* params, const char* uri)

if (factory->m_BaseArchiveMount)
{
dmResource::HManifest manifest;
if (dmResourceProvider::RESULT_OK == dmResourceProvider::GetManifest(factory->m_BaseArchiveMount, &manifest))
if (params->m_Flags & RESOURCE_FACTORY_FLAGS_LIVE_UPDATE)
{
char app_support_path[DMPATH_MAX_PATH];
if (RESULT_OK == dmResource::GetApplicationSupportPath(manifest, app_support_path, sizeof(app_support_path)))
dmResource::HManifest manifest;
if (dmResourceProvider::RESULT_OK == dmResourceProvider::GetManifest(factory->m_BaseArchiveMount, &manifest))
{
dmResourceMounts::LoadMounts(factory->m_Mounts, app_support_path);
char app_support_path[DMPATH_MAX_PATH];
if (RESULT_OK == dmResource::GetApplicationSupportPath(manifest, app_support_path, sizeof(app_support_path)))
{
dmResourceMounts::LoadMounts(factory->m_Mounts, app_support_path);
}
}
}
else
{
dmLogInfo("Resource mounts support disabled.");
}
}

dmLogDebug("Created resource factory with uri %s\n", uri);
Expand Down
1 change: 1 addition & 0 deletions scripts/copy_from_private_repo.py
Expand Up @@ -49,6 +49,7 @@
LOCAL_PATTERNS.append('build/')
LOCAL_PATTERNS.append('editor/target/classes/')
LOCAL_PATTERNS.append('dynamo_home')
LOCAL_PATTERNS.append('local_sdks')

def is_local_file(path):
for pattern in LOCAL_PATTERNS:
Expand Down