Skip to content

Commit

Permalink
Misc browse window functions (#492)
Browse files Browse the repository at this point in the history
* Implement filenameContainsInvalidChars (0x00446F1D)

* Correct mistake in sub_446574
  • Loading branch information
AaronVanGeffen committed May 29, 2020
1 parent 3189fca commit 690b0c4
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions src/openloco/windows/promptbrowsewnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace openloco::ui::prompt_browse
{
saved_game,
landscape,
unk_2,
};

#pragma pack(push, 1)
Expand Down Expand Up @@ -733,21 +732,43 @@ namespace openloco::ui::prompt_browse
});
}

static int sub_446F1D()
// 0x00446F1D
static bool filenameContainsInvalidChars()
{
return call(0x00446F1D) & X86_FLAG_CARRY;
uint8_t numNonSpacesProcessed = 0;
for (const char* ptr = &*_text_input_buffer; *ptr != '\0'; ptr++)
{
if (*ptr != ' ')
numNonSpacesProcessed++;

switch (*ptr)
{
// The following chars are considered invalid in filenames.
case '.':
case '"':
case '\\':
case '*':
case '?':
case ':':
case ';':
case ',':
case '<':
case '>':
case '/':
return true;
}
}

// If we have only processed spaces, the filename is invalid as well.
return numNonSpacesProcessed == 0;
}

// 0x00446574
static void sub_446574(ui::window* window)
{
if (*_type != browse_file_type::unk_2)
{
call(0x00446689);
}
else
if (*_type == browse_type::save)
{
if (sub_446F1D())
if (filenameContainsInvalidChars())
{
windows::show_error(string_ids::error_invalid_filename);
}
Expand All @@ -758,5 +779,11 @@ namespace openloco::ui::prompt_browse
call(0x00446598, regs);
}
}
else
{
registers regs;
regs.esi = (int32_t)window;
call(0x00446689, regs);
}
}
}

0 comments on commit 690b0c4

Please sign in to comment.