Skip to content

Commit

Permalink
Mac: adapt to upstream's changes to savefile
Browse files Browse the repository at this point in the history
  • Loading branch information
backwardsEric committed May 7, 2023
1 parent f2da429 commit 4fdf3e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/floor/floor-save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void check_saved_tmp_files(const int fd, bool *force)
void init_saved_floors(PlayerType *player_ptr, bool force)
{
auto fd = -1;
if (savefile[0]) {
if (!savefile.empty()) {
for (int i = 0; i < MAX_SAVED_FLOORS; i++) {
saved_floor_type *sf_ptr = &saved_floors[i];
std::string floor_savefile = get_saved_floor_name(i);
Expand Down
14 changes: 10 additions & 4 deletions src/main-cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3937,7 +3937,7 @@ static void set_color_for_index(int idx)
*/
static void record_current_savefile(void)
{
NSString *savefileString = [[NSString stringWithCString:savefile encoding:NSMacOSRomanStringEncoding] lastPathComponent];
NSString *savefileString = [[NSString stringWithCString:savefile.native().data() encoding:NSMacOSRomanStringEncoding] lastPathComponent];
if (savefileString)
{
NSUserDefaults *angbandDefs = [NSUserDefaults angbandDefaults];
Expand Down Expand Up @@ -5641,16 +5641,20 @@ - (IBAction)openGame:sender
if ([fileURLs count] > 0 && [[fileURLs objectAtIndex:0] isFileURL])
{
NSURL* savefileURL = (NSURL *)[fileURLs objectAtIndex:0];
char t[1024];

/*
* The path property doesn't do the right thing except for
* URLs with the file scheme. We had
* getFileSystemRepresentation here before, but that wasn't
* introduced until OS X 10.9.
*/
selectedSomething = [[savefileURL path]
getCString:savefile
maxLength:sizeof savefile
getCString:t
maxLength:sizeof(t)
encoding:NSMacOSRomanStringEncoding];
savefile = std::filesystem::path(t,
std::filesystem::path::native_format);
}
}

Expand Down Expand Up @@ -6279,11 +6283,13 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
}

/* Put it in savefile */
if (! [file getFileSystemRepresentation:savefile maxLength:sizeof savefile]) {
char t[1024];
if (! [file getFileSystemRepresentation:t maxLength:sizeof(t)]) {
[[NSApplication sharedApplication]
replyToOpenOrPrint:NSApplicationDelegateReplyFailure];
return;
}
savefile = std::filesystem::path(t, std::filesystem::path::native_format);

game_in_progress = YES;

Expand Down

0 comments on commit 4fdf3e8

Please sign in to comment.