Update to 1.10.0-beta1
This commit is contained in:
@@ -17,12 +17,11 @@
|
||||
#include "../script/squirrel.hpp"
|
||||
#include "script_scanner.hpp"
|
||||
#include "script_info.hpp"
|
||||
#include "script_fatalerror.hpp"
|
||||
|
||||
#if defined(ENABLE_NETWORK)
|
||||
#include "../network/network_content.h"
|
||||
#include "../3rdparty/md5/md5.h"
|
||||
#include "../tar_type.h"
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
@@ -30,19 +29,19 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const
|
||||
{
|
||||
free(this->main_script);
|
||||
this->main_script = stredup(filename);
|
||||
if (this->main_script == NULL) return false;
|
||||
if (this->main_script == nullptr) return false;
|
||||
|
||||
free(this->tar_file);
|
||||
if (tar_filename != NULL) {
|
||||
if (tar_filename != nullptr) {
|
||||
this->tar_file = stredup(tar_filename);
|
||||
if (this->tar_file == NULL) return false;
|
||||
if (this->tar_file == nullptr) return false;
|
||||
} else {
|
||||
this->tar_file = NULL;
|
||||
this->tar_file = nullptr;
|
||||
}
|
||||
|
||||
const char *end = this->main_script + strlen(this->main_script) + 1;
|
||||
char *p = strrchr(this->main_script, PATHSEPCHAR);
|
||||
if (p == NULL) {
|
||||
if (p == nullptr) {
|
||||
p = this->main_script;
|
||||
} else {
|
||||
/* Skip over the path separator character. We don't need that. */
|
||||
@@ -54,15 +53,19 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const
|
||||
if (!FioCheckFileExists(filename, this->subdir) || !FioCheckFileExists(this->main_script, this->subdir)) return false;
|
||||
|
||||
this->ResetEngine();
|
||||
this->engine->LoadScript(filename);
|
||||
|
||||
try {
|
||||
this->engine->LoadScript(filename);
|
||||
} catch (Script_FatalError &e) {
|
||||
DEBUG(script, 0, "Fatal error '%s' when trying to load the script '%s'.", e.GetErrorMessage(), filename);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ScriptScanner::ScriptScanner() :
|
||||
engine(NULL),
|
||||
main_script(NULL),
|
||||
tar_file(NULL)
|
||||
engine(nullptr),
|
||||
main_script(nullptr),
|
||||
tar_file(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -180,8 +183,6 @@ char *ScriptScanner::GetConsoleList(char *p, const char *last, bool newest_only)
|
||||
return p;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_NETWORK)
|
||||
|
||||
/** Helper for creating a MD5sum of all files within of a script. */
|
||||
struct ScriptFileChecksumCreator : FileScanner {
|
||||
byte md5sum[16]; ///< The final md5sum.
|
||||
@@ -207,7 +208,7 @@ struct ScriptFileChecksumCreator : FileScanner {
|
||||
|
||||
/* Open the file ... */
|
||||
FILE *f = FioFOpenFile(filename, "rb", this->dir, &size);
|
||||
if (f == NULL) return false;
|
||||
if (f == nullptr) return false;
|
||||
|
||||
/* ... calculate md5sum... */
|
||||
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
|
||||
@@ -245,7 +246,7 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
|
||||
ScriptFileChecksumCreator checksum(dir);
|
||||
const char *tar_filename = info->GetTarFile();
|
||||
TarList::iterator iter;
|
||||
if (tar_filename != NULL && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
|
||||
if (tar_filename != nullptr && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
|
||||
/* The main script is in a tar file, so find all files that
|
||||
* are in the same tar and add them to the MD5 checksumming. */
|
||||
TarFileList::iterator tar;
|
||||
@@ -255,7 +256,7 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S
|
||||
|
||||
/* Check the extension. */
|
||||
const char *ext = strrchr(tar->first.c_str(), '.');
|
||||
if (ext == NULL || strcasecmp(ext, ".nut") != 0) continue;
|
||||
if (ext == nullptr || strcasecmp(ext, ".nut") != 0) continue;
|
||||
|
||||
checksum.AddFile(tar->first.c_str(), 0, tar_filename);
|
||||
}
|
||||
@@ -285,7 +286,5 @@ const char *ScriptScanner::FindMainScript(const ContentInfo *ci, bool md5sum)
|
||||
for (ScriptInfoList::iterator it = this->info_list.begin(); it != this->info_list.end(); it++) {
|
||||
if (IsSameScript(ci, md5sum, (*it).second, this->GetDirectory())) return (*it).second->GetMainScript();
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
Reference in New Issue
Block a user