@@ -63,6 +63,7 @@ const char *ue4_module_options = "linux_global_symbols";
6363#endif
6464
6565#if PLATFORM_ANDROID
66+ #include " Misc/LocalTimestampDirectoryVisitor.h"
6667#include " Android/AndroidJNI.h"
6768#include " Android/AndroidApplication.h"
6869#endif
@@ -464,52 +465,50 @@ void FUnrealEnginePythonModule::StartupModule()
464465#if PY_MAJOR_VERSION >= 3
465466 init_unreal_engine_builtin ();
466467#if PLATFORM_ANDROID
467- extern FString GOBBFilePathBase ;
468- extern FString GFilePathBase;
468+ FString InDirectory = FString ( TEXT ( " Scripts " )) ;
469+
469470 extern FString GExternalFilePath;
470- extern FString GPackageName;
471- extern int32 GAndroidPackageVersion;
472- FString OBBDir1 = GOBBFilePathBase + FString (TEXT (" /Android/obb/" ) + GPackageName);
473- FString OBBDir2 = GOBBFilePathBase + FString (TEXT (" /obb/" ) + GPackageName);
474- FString MainOBBName = FString::Printf (TEXT (" main.%d.%s.obb" ), GAndroidPackageVersion, *GPackageName);
475- FString PatchOBBName = FString::Printf (TEXT (" patch.%d.%s.obb" ), GAndroidPackageVersion, *GPackageName);
476- FString UnrealEnginePython_OBBPath;
477- if (FPaths::FileExists (*(OBBDir1 / MainOBBName)))
478- {
479- UnrealEnginePython_OBBPath = OBBDir1 / MainOBBName / FApp::GetProjectName () / FString (TEXT (" Content/Scripts" ));
480- }
481- else if (FPaths::FileExists (*(OBBDir2 / MainOBBName)))
482- {
483- UnrealEnginePython_OBBPath = OBBDir2 / MainOBBName / FApp::GetProjectName () / FString (TEXT (" Content/Scripts" ));
484- }
485- if (FPaths::FileExists (*(OBBDir1 / PatchOBBName)))
486- {
487- UnrealEnginePython_OBBPath = OBBDir1 / PatchOBBName / FApp::GetProjectName () / FString (TEXT (" Content/Scripts" ));
488- }
489- else if (FPaths::FileExists (*(OBBDir2 / PatchOBBName)))
490- {
491- UnrealEnginePython_OBBPath = OBBDir1 / PatchOBBName / FApp::GetProjectName () / FString (TEXT (" Content/Scripts" ));
492- }
493471
494- if (!UnrealEnginePython_OBBPath.IsEmpty ())
495- {
496- ScriptsPaths.Add (UnrealEnginePython_OBBPath);
497- }
472+ FString DirectoryPath = FPaths::ProjectContentDir () / InDirectory;
473+
474+ IFileManager* FileManager = &IFileManager::Get ();
498475
499- FString FinalPath = GFilePathBase / FString (" UE4Game" ) / FApp::GetProjectName () / FApp::GetProjectName () / FString (TEXT (" Content/Scripts" ));
500- ScriptsPaths.Add (FinalPath);
476+ // iterate over all the files in provided directory
477+ FLocalTimestampDirectoryVisitor Visitor (FPlatformFileManager::Get ().GetPlatformFile (), TArray<FString>(),
478+ TArray<FString>(), false );
501479
502- FString BasePythonPath = FinalPath / FString ( TEXT ( " stdlib.zip " )) + FString ( " : " ) + FinalPath ;
480+ FileManager-> IterateDirectoryRecursively (*DirectoryPath, Visitor) ;
503481
504- if (!UnrealEnginePython_OBBPath.IsEmpty ())
482+ FString Prefix = FApp::GetProjectName () / FString (TEXT (" Content/Scripts/" ));
483+
484+ for (TMap<FString, FDateTime>::TIterator TimestampIt (Visitor.FileTimes ); TimestampIt; ++TimestampIt)
505485 {
506- BasePythonPath += FString (" :" ) + UnrealEnginePython_OBBPath;
486+ FString Path = TimestampIt.Key ();
487+
488+ Path.RemoveFromStart (Prefix);
489+
490+ // read the file contents and write it if successful to external path
491+ TArray<uint8> MemFile;
492+
493+ const FString SourceFilename = TimestampIt.Key ();
494+
495+ if (FFileHelper::LoadFileToArray (MemFile, *SourceFilename, 0 ))
496+ {
497+ FString DestFilename = GExternalFilePath / InDirectory / Path;
498+
499+ FFileHelper::SaveArrayToFile (MemFile, *DestFilename);
500+ }
507501 }
508502
509- UE_LOG (LogPython, Warning, TEXT ( " Setting Android Base Path to %s " ), *BasePythonPath) ;
503+ FString PyScriptsSearchPath = GExternalFilePath / InDirectory ;
510504
511- Py_SetPath (Py_DecodeLocale (TCHAR_TO_UTF8 (*BasePythonPath), NULL ));
512-
505+ ScriptsPaths.Reset ();
506+
507+ ScriptsPaths.Add (PyScriptsSearchPath);
508+
509+ UE_LOG (LogPython, Warning, TEXT (" Setting Android Python Scripts Search Path to %s" ), *PyScriptsSearchPath);
510+
511+ Py_SetPath (Py_DecodeLocale (TCHAR_TO_UTF8 (*PyScriptsSearchPath), NULL ));
513512#elif PLATFORM_IOS
514513 FString IOSContentPath = IFileManager::Get ().ConvertToAbsolutePathForExternalAppForRead (*IFileManager::Get ().GetFilenameOnDisk (*FPaths::ConvertRelativePathToFull (PROJECT_CONTENT_DIR)));
515514 FString PyScriptsSearchPath = IOSContentPath / FString (TEXT (" lib" )) + FString (" :" ) +
0 commit comments