Announcement

Collapse
No announcement yet.

How does "Additional Non-asset Directories to Package" work?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How does "Additional Non-asset Directories to Package" work?

    I want to read text file by C++ std API '"fopen", it's successful on Windows, but read failed on Android.
    Code:
    FString projectDir = FPaths::GameDir();
     FString path = projectDir + TEXT("Content/Resource/conf/role/Role.conf");
     FILE * fp = ::fopen(TCHAR_TO_ANSI(*path), "rb");
     
     if (fp)
     {
         TxtDebug->SetText(FText::FromString("TRUE++++++++++++"));
     }
     else
     {
         TxtDebug->SetText(FText::FromString("FALSE-----------"));
     }
    as I know, if there are some files should be inclued when Packaging, "Additional Non-asset Directories to Package" should be checked. even I check this setting, fopen still read file failed.

    Click image for larger version

Name:	80063-package-1.png
Views:	1
Size:	11.5 KB
ID:	1175317

    #2
    Hi DawnArc,

    The files are packaged so you cannot use low-level fopen to access them. You need to use the file system. The easiest way is to use LoadFileToString(), for example:

    Code:
    FString Contents;
    FString Filename = FPaths::GameContentDir() + TEXT("Resource/conf/role/Role.conf");
    if (FFileHelper::LoadFileToString(Contents, *Filename))
    {
    	// do something with Contents
    }
    You can look at the code for LoadFileToString() in Engine/Source/Runtime/Core/Private/Misc/CoreMisc.cpp to see how it works.

    Comment


      #3
      Originally posted by Chris Babcock View Post
      Hi DawnArc,

      The files are packaged so you cannot use low-level fopen to access them. You need to use the file system. The easiest way is to use LoadFileToString(), for example:

      Code:
      FString Contents;
      FString Filename = FPaths::GameContentDir() + TEXT("Resource/conf/role/Role.conf");
      if (FFileHelper::LoadFileToString(Contents, *Filename))
      {
      	// do something with Contents
      }
      You can look at the code for LoadFileToString() in Engine/Source/Runtime/Core/Private/Misc/CoreMisc.cpp to see how it works.
      ok, i see, thanks very much for your suggestions.

      Comment

      Working...
      X