Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Paths.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/StringView.h"
7#include "Containers/UnrealString.h"
8#include "CoreTypes.h"
9#include "HAL/CriticalSection.h"
10#include "Templates/UnrealTemplate.h"
11
12#include <type_traits>
13
14class FText;
15
16namespace UE::Core::Private
17{
18 const TCHAR* GetBindingType(const TCHAR* Ptr);
19 const FString& GetBindingType(const FString& Str);
20 const FStringView& GetBindingType(const FStringView& StringView);
21
22 // This is used to force the arguments of FString::Combine to implicitly convert (if necessary)
23 // to FString when calling CombineImpl(), allowing them to remain as temporaries on the stack
24 // so that they stay allocated during the combining process.
25 //
26 // Pointer arguments are passed without causing FString temporaries to be created,
27 // and FString arguments are referenced directly without creating extra copies.
28 template <typename T>
29 using TToStringType_T = decltype(GetBindingType(std::declval<T>()));
30}
31
32/**
33 * Path helpers for retrieving game dir, engine dir, etc.
34 */
35class FPaths
36{
37public:
38
39 /**
40 * Should the "saved" directory structures be rooted in the user dir or relative to the "engine/game"
41 */
42 static bool ShouldSaveToUserDir();
43
44 /**
45 * Returns the directory the application was launched from (useful for commandline utilities)
46 */
48
49 /**
50 * Returns the base directory of the "core" engine that can be shared across
51 * several games or across games & mods. Shaders and base localization files
52 * e.g. reside in the engine directory.
53 *
54 * @return engine directory
55 */
57
58 /**
59 * Returns the root directory for user-specific engine files. Always writable.
60 *
61 * @return root user directory
62 */
64
65 /**
66 * Returns the root directory for user-specific engine files which can be shared between versions. Always writable.
67 *
68 * @return root user directory
69 */
71
72 /**
73 * Returns the content directory of the "core" engine that can be shared across
74 * several games or across games & mods.
75 *
76 * @return engine content directory
77 */
79
80 /**
81 * Returns the directory the root configuration files are located.
82 *
83 * @return root config directory
84 */
86
87 /**
88 * Returns the Editor Settings directory of the engine
89 *
90 * @return Editor Settings directory.
91 */
93
94 /**
95 * Returns the intermediate directory of the engine
96 *
97 * @return content directory
98 */
100
101 /**
102 * Returns the saved directory of the engine
103 *
104 * @return Saved directory.
105 */
107
108 /**
109 * Returns the plugins directory of the engine
110 *
111 * @return Plugins directory.
112 */
114
115 /**
116 * Returns the directory for default Editor UI Layout files of the engine
117 * @return Directory for default Editor UI Layout files.
118 */
120
121 /**
122 * Returns the directory for project Editor UI Layout files of the engine
123 * @return Directory for project Editor UI Layout files.
124 */
126
127 /**
128 * Returns the directory for user-generated Editor UI Layout files of the engine
129 * @return Directory for user-generated Editor UI Layout files.
130 */
132
133 /**
134 * Returns the base directory enterprise directory.
135 *
136 * @return enterprise directory
137 */
139
140 /**
141 * Returns the enterprise plugins directory
142 *
143 * @return Plugins directory.
144 */
146
147 /**
148 * Returns the enterprise FeaturePack directory
149 *
150 * @return FeaturePack directory.
151 */
153
154 /**
155 * Returns the directory where engine platform extensions reside
156 *
157 * @return engine platform extensions directory
158 */
160
161 /**
162 * Returns the directory where the project's platform extensions reside
163 *
164 * @return project platform extensions directory
165 */
167
168 /**
169 * Returns platform and restricted extensions that are present and valid (for platforms, it uses FDataDrivePlatformInfo to determine valid platforms, it doesn't just use what's present)
170 *
171 * @return BaseDir and usable extension directories under BaseDir (either Engine or Project)
172 */
174
175 /**
176 * Returns the root directory of the engine directory tree
177 *
178 * @return Root directory.
179 */
180 static FString RootDir();
181
182#if WITH_EDITOR
183 /** Returns the special path used when mounting FeaturePaks in editor */
184 static const TCHAR* GameFeatureRootPrefix();
185#endif
186
187 /**
188 * Returns the base directory of the current project by looking at FApp::GetProjectName().
189 * This is usually a subdirectory of the installation
190 * root directory and can be overridden on the command line to allow self
191 * contained mod support.
192 *
193 * @return base directory
194 */
196
197 /**
198 * Returns the root directory for user-specific game files.
199 *
200 * @return game user directory
201 */
203
204 /**
205 * Returns the content directory of the current game by looking at FApp::GetProjectName().
206 *
207 * @return content directory
208 */
210
211 /**
212 * Returns the directory the root configuration files are located.
213 *
214 * @return root config directory
215 */
217
218 /**
219 * Returns the saved directory of the current game by looking at FApp::GetProjectName().
220 *
221 * @return saved directory
222 */
223 static const FString& ProjectSavedDir();
224
225 /**
226 * Returns the intermediate directory of the current game by looking at FApp::GetProjectName().
227 *
228 * @return intermediate directory
229 */
231
233
234 /**
235 * Returns the plugins directory of the current game by looking at FApp::GetProjectName().
236 *
237 * @return plugins directory
238 */
240
241 /**
242 * Returns the mods directory of the current project by looking at FApp::GetProjectName().
243 *
244 * @return mods directory
245 */
247
248 /*
249 * Returns true if a writable directory for downloaded data that persists across play sessions is available
250 */
252
253 /*
254 * Returns the writable directory for downloaded data that persists across play sessions.
255 */
257
258 /**
259 * Returns the directory the engine uses to look for the source leaf ini files. This
260 * can't be an .ini variable for obvious reasons.
261 *
262 * @return source config directory
263 */
265
266 /**
267 * Returns the directory the engine saves generated config files.
268 *
269 * @return config directory
270 */
272
273 /**
274 * Returns the directory the engine stores sandbox output
275 *
276 * @return sandbox directory
277 */
279
280 /**
281 * Returns the directory the engine uses to output profiling files.
282 *
283 * @return log directory
284 */
286
287 /**
288 * Returns the directory the engine uses to output screenshot files.
289 *
290 * @return screenshot directory
291 */
293
294 /**
295 * Returns the directory the engine uses to output BugIt files.
296 *
297 * @return screenshot directory
298 */
300
301 /**
302 * Returns the directory the engine uses to output user requested video capture files.
303 *
304 * @return Video capture directory
305 */
307
308 /**
309 * Returns the directory the engine uses to output user requested audio capture files.
310 *
311 * @return Audio capture directory
312 */
314
315 /**
316 * Returns the directory the engine uses to output logs. This currently can't
317 * be an .ini setting as the game starts logging before it can read from .ini
318 * files.
319 *
320 * @return log directory
321 */
323
324 /** Returns the directory for automation save files */
326
327 /** Returns the directory for automation save files that are meant to be deleted every run */
329
330 /** Returns the directory for results of automation tests. May be deleted every run. */
332
333 /** Returns the directory for automation log files */
335
336 /** Returns the directory for local files used in cloud emulation or support */
338
339 /**
340 * Returns the directory that contains subfolders for developer-specific content
341 * Example: "../../../ProjectName/Content/Developers
342 */
344
345 /**
346 * Returns the name of the subfolder for developer-specific content
347 * Example: "Developers"
348 */
349 static FStringView DevelopersFolderName();
350
351 /** Returns The folder name for the developer-specific directory for the current user */
353
354 /** Returns The directory that contains developer-specific content for the current user */
356
357 /** Returns the directory for temp files used for diffing */
358 static FString DiffDir();
359
360 /**
361 * Returns a list of engine-specific localization paths
362 */
364
365 /**
366 * Returns a list of editor-specific localization paths
367 */
369
370 /**
371 * Returns a list of cooked editor-specific localization paths
372 */
374
375 /**
376 * Returns a list of property name localization paths
377 */
379
380 /**
381 * Returns a list of tool tip localization paths
382 */
384
385 /**
386 * Returns a list of game-specific localization paths
387 */
389
390 /**
391 * Get the name of the platform-specific localization sub-folder
392 */
394
395 /**
396 * Returns a list of restricted/internal folder names (without any slashes) which may be tested against full paths to determine if a path is restricted or not.
397 */
399
400 /**
401 * Determines if supplied path uses a restricted/internal subdirectory. Note that slashes are normalized and character case is ignored for the comparison.
402 */
403 static bool IsRestrictedPath(const FString& InPath);
404
405 /**
406 * Returns the saved directory that is not game specific. This is usually the same as
407 * EngineSavedDir().
408 *
409 * @return saved directory
410 */
412
413 /** Returns the directory where engine source code files are kept */
415
416 /** Returns the directory where game source code files are kept */
418
419 /** Returns the directory where feature packs are kept */
421
422 /**
423 * Checks whether the path to the project file, if any, is set.
424 *
425 * @return true if the path is set, false otherwise.
426 */
427 static bool IsProjectFilePathSet();
428
429 /**
430 * Gets the path to the project file.
431 *
432 * @return Project file path.
433 */
435
436 /**
437 * Sets the path to the project file.
438 *
439 * @param NewGameProjectFilePath - The project file path to set.
440 */
441 static void SetProjectFilePath( const FString& NewGameProjectFilePath );
442
443 /**
444 * Gets the extension for this filename.
445 *
446 * @param bIncludeDot if true, includes the leading dot in the result
447 *
448 * @return the extension of this filename, or an empty string if the filename doesn't have an extension.
449 */
450 static FString GetExtension( const FString& InPath, bool bIncludeDot=false );
451
452 // Returns the filename (with extension), minus any path information.
453 static FString GetCleanFilename(const FString& InPath);
454
455 // Returns the filename (with extension), minus any path information.
457
458 // Returns the same thing as GetCleanFilename, but without the extension
459 static FString GetBaseFilename(const FString& InPath, bool bRemovePath=true );
460
461 // Returns the same thing as GetCleanFilename, but without the extension
462 static FString GetBaseFilename(FString&& InPath, bool bRemovePath = true);
463
464 // Returns the path in front of the filename
465 static FString GetPath(const FString& InPath);
466
467 // Returns the path in front of the filename
468 static FString GetPath(FString&& InPath);
469
470 // Returns the leaf in the path
471 static FString GetPathLeaf(const FString& InPath);
472
473 // Returns the leaf in the path
474 static FString GetPathLeaf(FString&& InPath);
475
476 /** Changes the extension of the given filename (does nothing if the file has no extension) */
477 static FString ChangeExtension(const FString& InPath, const FString& InNewExtension);
478
479 /** Sets the extension of the given filename (like ChangeExtension, but also applies the extension if the file doesn't have one) */
480 static FString SetExtension(const FString& InPath, const FString& InNewExtension);
481
482 /** Returns true if this file was found, false otherwise */
483 static bool FileExists(const FString& InPath);
484
485 /** Returns true if this directory was found, false otherwise */
486 static bool DirectoryExists(const FString& InPath);
487
488 /** Returns true if this path represents a root drive or volume */
489 static bool IsDrive(const FString& InPath);
490
491 /** Returns true if this path is relative to another path */
492 static bool IsRelative(const FString& InPath);
493
494 /** Convert all / and \ to TEXT("/") */
495 static void NormalizeFilename(FString& InPath);
496
497 /**
498 * Checks if two paths are the same.
499 *
500 * @param PathA First path to check.
501 * @param PathB Second path to check.
502 *
503 * @returns True if both paths are the same. False otherwise.
504 */
505 static bool IsSamePath(const FString& PathA, const FString& PathB);
506
507 /** Determines if a path is under a given directory */
508 static bool IsUnderDirectory(const FString& InPath, const FString& InDirectory);
509
510 /** Normalize all / and \ to TEXT("/") and remove any trailing TEXT("/") if the character before that is not a TEXT("/") or a colon */
511 static void NormalizeDirectoryName(FString& InPath);
512
513 /**
514 * Takes a fully pathed string and eliminates relative pathing (eg: annihilates ".." with the adjacent directory).
515 * Assumes all slashes have been converted to TEXT('/').
516 * For example, takes the string:
517 * BaseDirectory/SomeDirectory/../SomeOtherDirectory/Filename.ext
518 * and converts it to:
519 * BaseDirectory/SomeOtherDirectory/Filename.ext
520 */
522
523 /**
524 * Removes duplicate slashes in paths.
525 * Assumes all slashes have been converted to TEXT('/').
526 * For example, takes the string:
527 * BaseDirectory/SomeDirectory//SomeOtherDirectory////Filename.ext
528 * and converts it to:
529 * BaseDirectory/SomeDirectory/SomeOtherDirectory/Filename.ext
530 */
531 static void RemoveDuplicateSlashes(FString& InPath);
532
533 /** Returns a copy of the given path on which duplicate slashes were removed (see the inplace version for more details). */
535
536 /**
537 * Make fully standard "Unreal" pathname:
538 * - Normalizes path separators [NormalizeFilename]
539 * - Removes extraneous separators [NormalizeDirectoryName, as well removing adjacent separators]
540 * - Collapses internal ..'s
541 * - Makes relative to Engine\Binaries<Platform> (will ALWAYS start with ..\..\..)
542 */
544
545 static void MakeStandardFilename(FString& InPath);
546
547 /** Takes an "Unreal" pathname and converts it to a platform filename. */
548 static void MakePlatformFilename(FString& InPath);
549
550 /**
551 * Assuming both paths (or filenames) are relative to the same base dir, modifies InPath to be relative to InRelativeTo
552 *
553 * @param InPath Path to change to be relative to InRelativeTo
554 * @param InRelativeTo Path to use as the new relative base
555 * @returns true if InPath was changed to be relative
556 */
557 static bool MakePathRelativeTo( FString& InPath, const TCHAR* InRelativeTo );
558
559 /**
560 * Converts a relative path name to a fully qualified name relative to the process BaseDir().
561 */
563
564 /**
565 * Converts a relative path name to a fully qualified name relative to the process BaseDir().
566 */
568
569 /**
570 * Converts a relative path name to a fully qualified name relative to the specified BasePath.
571 */
572 static FString ConvertRelativePathToFull(const FString& BasePath, const FString& InPath);
573
574 /**
575 * Converts a relative path name to a fully qualified name relative to the specified BasePath.
576 */
577 static FString ConvertRelativePathToFull(const FString& BasePath, FString&& InPath);
578
579 /**
580 * Converts a relative path name to a fully qualified name relative to the specified BasePath.
581 */
582 static FString ConvertRelativePathToFull(FString&& BasePath, const FString& InPath);
583
584 /**
585 * Converts a relative path name to a fully qualified name relative to the specified BasePath.
586 */
587 static FString ConvertRelativePathToFull(FString&& BasePath, FString&& InPath);
588
589 /**
590 * Converts a normal path to a sandbox path (in Saved/Sandboxes).
591 *
592 * @param InSandboxName The name of the sandbox.
593 */
594 static FString ConvertToSandboxPath( const FString& InPath, const TCHAR* InSandboxName );
595
596 /**
597 * Converts a sandbox (in Saved/Sandboxes) path to a normal path.
598 *
599 * @param InSandboxName The name of the sandbox.
600 */
601 static FString ConvertFromSandboxPath( const FString& InPath, const TCHAR* InSandboxName );
602
603 /**
604 * Creates a temporary filename with the specified prefix.
605 *
606 * @param Path The file pathname.
607 * @param Prefix The file prefix.
608 * @param Extension File extension ('.' required).
609 */
610 static FString CreateTempFilename( const TCHAR* Path, const TCHAR* Prefix = TEXT(""), const TCHAR* Extension = TEXT(".tmp") );
611
612 /**
613 * Returns a string containing all invalid characters as dictated by the operating system
614 */
616
617 /**
618 * Returns a string that is safe to use as a filename because all items in
619 * GetInvalidFileSystemChars() are removed
620 */
621 static FString MakeValidFileName(const FString& InString, const TCHAR InReplacementChar = TEXT('\0'));
622
623 /**
624 * Validates that the parts that make up the path contain no invalid characters as dictated by the operating system
625 * Note that this is a different set of restrictions to those imposed by FPackageName
626 *
627 * @param InPath - path to validate
628 * @param OutReason - optional parameter to fill with the failure reason
629 */
630 static bool ValidatePath( const FString& InPath, FText* OutReason = nullptr );
631
632 /**
633 * Parses a fully qualified or relative filename into its components (filename, path, extension).
634 *
635 * @param InPath [in] Full filename path
636 * @param PathPart [out] receives the value of the path portion of the input string
637 * @param FilenamePart [out] receives the value of the filename portion of the input string
638 * @param ExtensionPart [out] receives the value of the extension portion of the input string
639 */
640 static void Split( const FString& InPath, FString& PathPart, FString& FilenamePart, FString& ExtensionPart );
641
642 /** Gets the relative path to get from BaseDir to RootDirectory */
644
645 template <typename... PathTypes>
646 FORCEINLINE static FString Combine(PathTypes&&... InPaths)
647 {
649 }
650
651#if 0
653 {
655 FString Out;
656
658 return Out;
659 }
660
661 FORCEINLINE static FString Combine(const FString& Path1, const TCHAR* PathMid, const FStringView& Path2)
662 {
664 FString Out;
665
667 return Out;
668 }
669#endif
670
671 /**
672 * Frees any memory retained by FPaths.
673 */
674 static void TearDown();
675
676protected:
677
678 static void CombineInternal(FString& OutPath, const FStringView* Paths, int32 NumPaths);
679
680private:
681 struct FStaticData;
682
683 template <typename... PathTypes>
684 FORCEINLINE static FString CombineImpl(UE::Core::Private::TToStringType_T<std::decay_t<PathTypes>>... InPaths)
685 {
686 const FStringView Paths[] = { FStringView(InPaths)... };
687 FString Out;
688
690 return Out;
691 }
692
693 /** Returns, if any, the value of the -userdir command line argument. This can be used to sandbox artifacts to a desired location */
695
696 /** Returns, if any, the value of the -shaderworkingdir command line argument. This can be used to sandbox shader working files to a desired location */
698};
#define WITH_EDITOR
Definition Build.h:7
#define TEXT(x)
Definition Platform.h:1108
#define FORCEINLINE
Definition Platform.h:644
#define UE_ARRAY_COUNT(array)
Definition Paths.h:36
static FString CreateTempFilename(const TCHAR *Path, const TCHAR *Prefix=TEXT(""), const TCHAR *Extension=TEXT(".tmp"))
static bool IsProjectFilePathSet()
static FString GetPath(FString &&InPath)
static FString SetExtension(const FString &InPath, const FString &InNewExtension)
static FString FeaturePackDir()
static FString DiffDir()
static const FString & GetRelativePathToRoot()
static const FString & CustomShaderDirArgument()
static FString EngineDir()
static FString GetExtension(const FString &InPath, bool bIncludeDot=false)
static FString CreateStandardFilename(const FString &InPath)
static FString EnginePluginsDir()
static FString EnterpriseFeaturePackDir()
static TArray< FString > GetExtensionDirs(const FString &BaseDir, const FString &SubDir=FString())
static void NormalizeDirectoryName(FString &InPath)
static const TArray< FString > & GetCookedEditorLocalizationPaths()
static FString ConvertRelativePathToFull(FString &&BasePath, const FString &InPath)
static FString ScreenShotDir()
static FString AudioCaptureDir()
static FString ChangeExtension(const FString &InPath, const FString &InNewExtension)
static FString GetBaseFilename(FString &&InPath, bool bRemovePath=true)
static FString ProjectLogDir()
static FString MakeValidFileName(const FString &InString, const TCHAR InReplacementChar=TEXT('\0'))
static bool IsDrive(const FString &InPath)
static FString GetPathLeaf(const FString &InPath)
static FString ProjectPersistentDownloadDir()
static FString GeneratedConfigDir()
static bool IsRelative(const FString &InPath)
static FString AutomationLogDir()
static FString GetProjectFilePath()
static void SetProjectFilePath(const FString &NewGameProjectFilePath)
static FString RemoveDuplicateSlashes(const FString &InPath)
static FString GetPath(const FString &InPath)
static bool ShouldSaveToUserDir()
static const TArray< FString > & GetRestrictedFolderNames()
static FString EngineConfigDir()
static FString AutomationTransientDir()
static void MakePlatformFilename(FString &InPath)
static FString ProjectIntermediateDir()
static void Split(const FString &InPath, FString &PathPart, FString &FilenamePart, FString &ExtensionPart)
static FString ProjectPlatformExtensionsDir()
static FORCEINLINE FString CombineImpl(UE::Core::Private::TToStringType_T< std::decay_t< PathTypes > >... InPaths)
Definition Paths.h:684
static FString GameSourceDir()
static FString EngineContentDir()
static bool ValidatePath(const FString &InPath, FText *OutReason=nullptr)
static FString GameUserDeveloperDir()
static const TArray< FString > & GetGameLocalizationPaths()
static FString ProjectPluginsDir()
static FString GetPathLeaf(FString &&InPath)
static FString EngineSavedDir()
static FString ConvertFromSandboxPath(const FString &InPath, const TCHAR *InSandboxName)
static bool DirectoryExists(const FString &InPath)
static FString EngineDefaultLayoutDir()
static FString ProjectConfigDir()
static FString GameAgnosticSavedDir()
static FString ConvertRelativePathToFull(FString &&InPath)
static const TArray< FString > & GetToolTipLocalizationPaths()
static FString EngineVersionAgnosticUserDir()
static FString ProfilingDir()
static FString GetInvalidFileSystemChars()
static void NormalizeFilename(FString &InPath)
static bool IsSamePath(const FString &PathA, const FString &PathB)
static bool HasProjectPersistentDownloadDir()
static FString GetCleanFilename(const FString &InPath)
static FString ConvertRelativePathToFull(const FString &BasePath, FString &&InPath)
static FString AutomationReportsDir()
static const TArray< FString > & GetEngineLocalizationPaths()
static FString EngineEditorSettingsDir()
static FORCEINLINE FString Combine(PathTypes &&... InPaths)
Definition Paths.h:646
static void RemoveDuplicateSlashes(FString &InPath)
static FString EngineProjectLayoutDir()
static void TearDown()
static FString ConvertToSandboxPath(const FString &InPath, const TCHAR *InSandboxName)
static FString EngineUserLayoutDir()
static FString BugItDir()
static bool MakePathRelativeTo(FString &InPath, const TCHAR *InRelativeTo)
static void CombineInternal(FString &OutPath, const FStringView *Paths, int32 NumPaths)
static FString ConvertRelativePathToFull(const FString &InPath)
static FString EnterpriseDir()
static bool CollapseRelativeDirectories(FString &InPath)
static FString EngineUserDir()
static FString RootDir()
static FString LaunchDir()
static const TArray< FString > & GetEditorLocalizationPaths()
static bool IsUnderDirectory(const FString &InPath, const FString &InDirectory)
static FString CloudDir()
static FString GetPlatformLocalizationFolderName()
static FString AutomationDir()
static FString GameUserDeveloperFolderName()
static const FString & CustomUserDirArgument()
static const TArray< FString > & GetPropertyNameLocalizationPaths()
static FString ProjectContentDir()
static bool FileExists(const FString &InPath)
static FString ConvertRelativePathToFull(const FString &BasePath, const FString &InPath)
static FString ConvertRelativePathToFull(FString &&BasePath, FString &&InPath)
static FString GameDevelopersDir()
static FString SandboxesDir()
static FString ProjectDir()
static FString VideoCaptureDir()
static FString ShaderWorkingDir()
static FString GetBaseFilename(const FString &InPath, bool bRemovePath=true)
static FString EnterprisePluginsDir()
static FString GetCleanFilename(FString &&InPath)
static FString EngineIntermediateDir()
static FStringView DevelopersFolderName()
static FString ProjectUserDir()
static bool IsRestrictedPath(const FString &InPath)
static FString SourceConfigDir()
static FString EnginePlatformExtensionsDir()
static const FString & ProjectSavedDir()
static void MakeStandardFilename(FString &InPath)
static FString ProjectModsDir()
static FString EngineSourceDir()
Definition Text.h:357
const FStringView & GetBindingType(const FStringView &StringView)
const FString & GetBindingType(const FString &Str)
const TCHAR * GetBindingType(const TCHAR *Ptr)
Definition Vector.h:40
Definition json.hpp:4518