diasurgical / devilutionX

Diablo build for modern operating systems
Other
8.11k stars 796 forks source link

iOS not generating documents folder #5796

Closed 616dustin closed 1 year ago

616dustin commented 1 year ago

Operating System

iOS

DevilutionX version

1.4.1 (latest release)

Describe

Sideloaded via Altstore, launched DevilutionX, received a "Data File Error" warning. "Unable to open main data archive (diabdat.mpq or spawn.mpq

Make sure it is in the game folder"

i click OK and close the app then open files.app and go to "On My iPhone" and there is no DevilutionX folder.

I tried creating the folder and adding the mpq's but i receive the same error.

To Reproduce

  1. Download devilutionx-ios.ipa
  2. Upload devilutionx-ios.ipa to icloud folder.
  3. In AltStore add devilutionx-ios.ipa for sideloading
  4. launch devilutionx
  5. receive missing mpq error
  6. close devilutionx
  7. open files.app
  8. Under Locations choose "On My iPhone"
  9. no folder found for devilutionx
  10. also tried searching in files.app for devilutionx and no results returned.

Expected Behavior

there should be a devilutionx folder to upload the mpq's to.

Additional context

iPhone 14 Pro Max iOS Version: 16.0.3

AJenbo commented 1 year ago

@bubio do you have an idea what could be the issue here?

bubio commented 1 year ago

@616dustin Try to make the file name diabdat.mpq or spawn.mpq all uppercase! (DIABDAT.MPQ)

DakkJaniels commented 1 year ago

@616dustin Try to make the file name diabdat.mpq or spawn.mpq all uppercase! (DIABDAT.MPQ)

How would that help if there is no DevilutionX folder?

bubio commented 1 year ago

@616dustin

I tried with the master repository, but there is no folder. Try Method 2 or Method 3 in the following document.

https://github.com/diasurgical/devilutionX/blob/master/docs/installing.md

bubio commented 1 year ago

@AJenbo

If the Document folder in the app bundle is empty, files.app doesn't seem to see the folder. At present, Method 1 cannot be used. It may be good if the generation timing of diablo.ini can be advanced.

616dustin commented 1 year ago

@bubio Method 2 worked for me. Oddly when i first launched it i received a warning that not all hellfire mpq's were found, even though i have the 4 hellfire mpqs. upon restarting the app everything seems to work great, thank you!

bubio commented 1 year ago

@AJenbo

If the Document folder is empty, I guess one solution would be to create an empty hidden file.


char *IOSGetPrefPath()
{
    @autoreleasepool {
        NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        if ([array count] > 0) {
            NSString *str = [array objectAtIndex:0];

            // Countermeasure for the problem that folders are not displayed in iOS file.app when the Document folder is empty.
            // Create an empty hidden file.
            NSFileManager *fm = [NSFileManager defaultManager];
            NSArray *files = [fm contentsOfDirectoryAtPath:str error:nil];
            if ([files count] == 0) {
                NSString *keepFile = [str stringByAppendingPathComponent:@".reveal"];
                [fm createFileAtPath:keepFile contents:nil attributes:nil];
            }

            str = [str stringByAppendingString:@"/"];
            const char *base = [str fileSystemRepresentation];

            char *copy = malloc(strlen(base) + 1);
            strcpy(copy, base);
            return copy;
        }

        return "";
    }
}

IMG_5242

AJenbo commented 1 year ago

we do that on startup and then delete it

AJenbo commented 1 year ago

can you test the latest build?

bubio commented 1 year ago

@AJenbo

5814

I built the latest source code and tried it, but the folder did not show up in files.app.

IMG_55746D4FC5ED-1

AJenbo commented 1 year ago

It's odd because SaveOptions() is called just before showing the intro and menu: https://github.com/diasurgical/devilutionX/blob/master/Source/diablo.cpp#L2424

Maybe we need to change it so that it will will see the ini file as changed if there isn't an ini file yet: https://github.com/diasurgical/devilutionX/blob/928d00e9a8dc2f3f0276145cb00cec296ffdbbe9/Source/options.cpp#L237

bubio commented 1 year ago

After displaying an error dialog, the program terminates immediately.

https://github.com/diasurgical/devilutionX/blob/53975d9264fb9a4d5ab5a613674b37794085203f/Source/appfat.cpp#L82

bubio commented 1 year ago

Although aggressive, the following will create an ini file and display the Document folder.

void diablo_quit(int exitStatus)
{
    SaveOptions(); // <- Add this line
    FreeGameMem();
    music_stop();
    DiabloDeinit();
    exit(exitStatus);
}
StephenCWills commented 1 year ago

It's odd because SaveOptions() is called just before showing the intro and menu: https://github.com/diasurgical/devilutionX/blob/master/Source/diablo.cpp#L2424

It's because the game crashes on the call to LoadGameArchives() a few lines above that.

StephenCWills commented 1 year ago

we do that on startup and then delete it

I think you're talking about the call to ReadOnlyTest() in DiabloInit(), which is also called just a bit too late. The game just doesn't bother trying to create any files if it can't find the game data in LoadGameArchives().

We could pull ReadOnlyTest() out of DiabloInit() and call it directly in DiabloMain(). That would allow us to create the temp file before loading the game archives. However, I think the reason we call them in that order is because we can't display the proper error dialog until the main window has been created.

bubio commented 1 year ago

If the Document folder is empty, it will not appear in files.app, so some file must be created in the Document folder. ReadOnlyTest() will delete the file it created, right?

StephenCWills commented 1 year ago

Yes, it will. So what you're saying is, we can't resolve this issue using ReadOnlyTest() because the folder will be empty again after the temp file is deleted, right?

bubio commented 1 year ago

Yes, it will. So what you're saying is, we can't resolve this issue using ReadOnlyTest() because the folder will be empty again after the temp file is deleted, right?

That’s correct.