Agrarsense
AgrarsensePaths.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#include "AgrarsensePaths.h"
7
8#include "Misc/Paths.h"
9#include "HAL/FileManagerGeneric.h"
10#include "Containers/StringConv.h"
11#include "Async/Async.h"
12
13#include "IDesktopPlatform.h"
14
16
18{
19 FString ProjectRootPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
20
21 // How many characters to remove so we get Actual project root folder
22 int CharsToRemove = 11;
23#if WITH_EDITOR
24 CharsToRemove = 18;
25#endif
26
27 ProjectRootPath.RemoveAt(ProjectRootPath.Len() - CharsToRemove, CharsToRemove, true);
28
29 return ProjectRootPath;
30}
31
33{
34 FString RootPath = GetProjectRootFolder();
35 FString ContentFolder = RootPath + "Unreal/Agrarsense/Content/";
36
37 return ContentFolder;
38}
39
41{
42 if (!DataPathForThisRun.IsEmpty())
43 {
44 return DataPathForThisRun;
45 }
46
47 IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
48
49 FString RootPath = GetProjectRootFolder();
50 FString DataRoot = RootPath + "Data";
51
52 if (!FPaths::DirectoryExists(DataRoot))
53 {
54 PlatformFile.CreateDirectory(*DataRoot);
55 }
56
57 // Continue with the rest of the logic
58 FString BaseDataFolderPath = DataRoot + "/Run";
59
60 int32 RunIndex = 0;
61 do
62 {
63 DataPathForThisRun = BaseDataFolderPath + FString::FromInt(RunIndex);
64 RunIndex++;
65 } while (PlatformFile.DirectoryExists(*DataPathForThisRun));
66
67 DataPathForThisRun += "/"; // Append slash to the path
68
69 PlatformFile.CreateDirectory(*DataPathForThisRun);
70
71 return DataPathForThisRun;
72}
73
75{
76 FString RootPath = GetProjectRootFolder();
77
78 FString DataFolderPath = RootPath + "Examples/";
79
80 // Check if dir exists, if it doesn't let's create it.
81 IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
82 if (!PlatformFile.DirectoryExists(*DataFolderPath))
83 {
84 PlatformFile.CreateDirectory(*DataFolderPath);
85 }
86
87 return DataFolderPath;
88}
static FString GetContentFolderPath()
static FString GetDataFolder()
static FString GetProjectRootFolder()
static FString DataPathForThisRun
static FString GetExamplesFolder()