Skip to content

Commit

Permalink
Continue execution if the file cannot be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Cowboy-69 committed Sep 5, 2024
1 parent 81d1714 commit 47ab2fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion FileSystemRedux.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>cleo_redux.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib/cleo_redux.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down
35 changes: 24 additions & 11 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class FileSystemPlugin {
files[fileID].open(filePathName, std::ios_base::app);

if (!files[fileID].good()) {
Log("FileSystem.cleo: ERROR - Could not open file!");
return HandlerResult::ERR;
Log("FileSystem.cleo: WARNING - Could not open file! [OPEN_FILE]");

SetIntParam(ctx, -1);
return HandlerResult::CONTINUE;
}

bIsFileOpen = true;
Expand All @@ -39,21 +41,27 @@ class FileSystemPlugin {
}

if (!bIsFileOpen) {
Log("FileSystem.cleo: ERROR - Could not open file!");
return HandlerResult::ERR;
Log("FileSystem.cleo: WARNING - Could not open file! [OPEN_FILE]");

SetIntParam(ctx, -1);
return HandlerResult::CONTINUE;
}

SetIntParam(ctx, fileID);

return HandlerResult::CONTINUE;
}

static HandlerResult CloseFile(Context ctx) {
int fileID = GetIntParam(ctx);

if (fileID < 0 || fileID >= MAX_FILES || !files[fileID].is_open()) {
Log("FileSystem.cleo: ERROR - This file does not exist!");
return HandlerResult::ERR;
if (fileID < 0 || fileID >= MAX_FILES) {
Log("FileSystem.cleo: WARNING - This file does not exist! [CLOSE_FILE]");
return HandlerResult::CONTINUE;
}

if (!files[fileID].is_open()) {
Log("FileSystem.cleo: WARNING - This file does not exist! [CLOSE_FILE]");
return HandlerResult::CONTINUE;
}

files[fileID].close();
Expand All @@ -64,9 +72,14 @@ class FileSystemPlugin {
static HandlerResult WriteStringToFile(Context ctx) {
int fileID = GetIntParam(ctx);

if (fileID < 0 || fileID >= MAX_FILES || !files[fileID].is_open()) {
Log("FileSystem.cleo: ERROR - This file does not exist!");
return HandlerResult::ERR;
if (fileID < 0 || fileID >= MAX_FILES) {
Log("FileSystem.cleo: WARNING - This file does not exist! [WRITE_STRING_TO_FILE]");
return HandlerResult::CONTINUE;
}

if (!files[fileID].is_open()) {
Log("FileSystem.cleo: WARNING - This file does not exist! [WRITE_STRING_TO_FILE]");
return HandlerResult::CONTINUE;
}

char line[STR_MAX_LEN];
Expand Down

0 comments on commit 47ab2fd

Please sign in to comment.