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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
@@ -116,6 +117,7 @@ namespace dmLiveUpdate | |
dmResource::HFactory m_ResourceFactory; // Resource system factory | ||
dmResourceProvider::HArchive m_LiveupdateArchive; | ||
dmResource::HManifest m_LiveupdateArchiveManifest; | ||
bool m_IsEnabled; | ||
|
||
} g_LiveUpdate; | ||
|
||
|
@@ -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) | ||
{ | ||
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's depending on context. I personally think that a scope (curly braces) isn't needed when all we do is return a value. Assignments may be different. |
||
return RESULT_NOT_INITIALIZED; | ||
|
||
if (resource->m_Data == 0x0) | ||
{ | ||
return RESULT_MEM_ERROR; | ||
|
@@ -490,7 +501,7 @@ namespace dmLiveUpdate | |
return RESULT_INVALID_RESOURCE; | ||
} | ||
|
||
if(IsLiveupdateDisabled()) | ||
if(IsLiveupdateThreadDisabled()) | ||
{ | ||
return RESULT_INVAL; | ||
} | ||
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
||
|
There was a problem hiding this comment.
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