Advertisement
dominus

Untitled

Sep 10th, 2024
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.89 KB | None | 0 0
  1. diff --git a/files/utils.cc b/files/utils.cc
  2. index 764f95105..e39cfce35 100644
  3. --- a/files/utils.cc
  4. +++ b/files/utils.cc
  5. @@ -792,9 +792,14 @@ void setup_data_dir(const std::string& data_path, const char* runpath) {
  6.     if (is_system_path_defined("<BUNDLE>")) {
  7.         // We have the flxfiles in the bundle, so lets use it.
  8.         // But lets use <DATA> in the iTunes file sharing.
  9. -       string path(IOSGetDocumentsDir());
  10. +       bool has_data = false;
  11. +       string path(IOSGetDocumentsDir(&has_data));
  12.         path += "/data";
  13.         add_system_path("<DATA>", path);
  14. +       if(!has_data) {
  15. +           string source_data_dir = "./data/game";
  16. +           copy_data_to_documents_dir(source_data_dir.c_str());
  17. +       }
  18.         return;
  19.     }
  20.  #endif
  21. diff --git a/ios/include/ios_utils.h b/ios/include/ios_utils.h
  22. index c6dca6b62..6093e332c 100644
  23. --- a/ios/include/ios_utils.h
  24. +++ b/ios/include/ios_utils.h
  25. @@ -34,6 +34,7 @@ class TouchUI_iOS : public TouchUI {
  26.     void onDpadLocationChanged() final;
  27.  };
  28.  
  29. -const char* IOSGetDocumentsDir();
  30. +const char* IOSGetDocumentsDir(bool * = NULL);
  31. +void copy_data_to_documents_dir(const char *);
  32.  
  33.  #endif
  34. diff --git a/ios/ios_utils.mm b/ios/ios_utils.mm
  35. index d18e3db96..0241d9197 100644
  36. --- a/ios/ios_utils.mm
  37. +++ b/ios/ios_utils.mm
  38. @@ -274,15 +274,45 @@ - (void)hideButtonControls {
  39.  
  40.  /* ---------------------------------------------------------------------- */
  41.  
  42. -const char* IOSGetDocumentsDir() {
  43. +const char* IOSGetDocumentsDir(bool * hasData) {
  44. +   NSString *docDirectory = nil;
  45.     if (gDocsDir[0] == 0) {
  46.         NSArray* paths = NSSearchPathForDirectoriesInDomains(
  47.                 NSDocumentDirectory, NSUserDomainMask, YES);
  48. -       NSString* docDirectory = [paths objectAtIndex:0];
  49. +       docDirectory = [paths objectAtIndex:0];
  50.         strcpy(gDocsDir, docDirectory.UTF8String);
  51.         printf("Documents: %s\n", gDocsDir);
  52.         // chdir(gDocsDir);
  53.         // *strncpy(gDocsDir, , sizeof(gDocsDir) - 1) = 0;
  54.     }
  55. +   if (hasData) {
  56. +       if(!docDirectory) {
  57. +           NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  58. +           docDirectory = [paths objectAtIndex:0];
  59. +       }
  60. +
  61. +       BOOL isDir = NO;
  62. +       if([[NSFileManager defaultManager] fileExistsAtPath:[docDirectory stringByAppendingPathComponent:@"game"] isDirectory:&isDir]) {
  63. +           if(isDir) {
  64. +               *hasData = YES;
  65. +               return gDocsDir;
  66. +           }
  67. +       }
  68. +       *hasData = NO;
  69. +   }
  70.     return gDocsDir;
  71.  }
  72. +
  73. +void copy_data_to_documents_dir(const char * path)
  74. +{
  75. +   bool has_data = false;
  76. +   NSString * src = [NSString stringWithUTF8String:path];
  77. +   NSString * dest = [NSString stringWithUTF8String:IOSGetDocumentsDir(&has_data)];
  78. +   NSError * err = nil;
  79. +   BOOL result = [[NSFileManager defaultManager] copyItemAtPath:src toPath:[dest stringByAppendingPathComponent:@"game"] error:&err];
  80. +   if(!result) {
  81. +       NSLog(@"Error copying data to documents directory: %@", err);
  82. +   } else {
  83. +       NSLog(@"Copied game data to documents directory.");
  84. +   }
  85. +}
  86. \ No newline at end of file
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement