LkEngine 0.1.2
 
Loading...
Searching...
No Matches
File.h
1#pragma once
2
3#if 0
4#include <string>
5#include <filesystem>
6
7#include <stb/stb_image.h>
8#include <stb/stb_image_resize2.h>
9
10#include "LkEngine/Core/Memory/MemoryUtils.h"
11
12namespace LkEngine {
13
14 enum class EFileExtension
15 {
16 Unknown = -1,
17 PNG = 3,
18 JPG = 3,
19 LUA = 3,
20 PY = 2
21 };
22
23 enum class EFileExtensionLength
24 {
25 None = 0,
26 PNG = 3,
27 JPG = 3,
28 LUA = 3,
29 PY = 2
30 };
31
32 class LFile
33 {
34 public:
35 LFile(const std::string& InFilePath);
36 ~LFile() = default;
37
38 template<typename T>
39 FORCEINLINE static bool DoesFileExist(T FilePath)
40 {
41 LK_UNUSED(FilePath);
42 return false;
43 }
44
45 template<>
46 FORCEINLINE static bool DoesFileExist(std::string_view InFilePath)
47 {
48 return std::filesystem::exists(InFilePath) && !std::filesystem::is_directory(InFilePath);
49 }
50
51 template<>
52 FORCEINLINE static bool DoesFileExist(std::filesystem::path InFilePath)
53 {
54 return std::filesystem::exists(InFilePath) && !std::filesystem::is_directory(InFilePath);
55 }
56
57 #if 0
61 FORCEINLINE static bool DoesFileExist(std::string_view InFilePath)
62 {
63 return std::filesystem::exists(InFilePath) && !std::filesystem::is_directory(InFilePath);
64 }
65 #endif
66
70 FORCEINLINE static bool HasFileExtension(const std::string& filename)
71 {
72 size_t pos = filename.rfind('.');
73 if (pos == std::string::npos)
74 {
75 return false;
76 }
77
78 return true;
79 }
80
81 static std::string ExtractFilename(std::string_view InFilePath)
82 {
83 const size_t Pos = InFilePath.find_last_of("/\\");
84 if (Pos != std::string::npos)
85 {
86 return std::string(InFilePath.substr(Pos + 1));
87 }
88
89 return {};
90 }
91
92 static int GetFilesInDirectory(std::string_view Directory, std::vector<LFile>& Files);
93
94 FORCEINLINE std::string GetName() const { return Name; }
95 FORCEINLINE std::string GetPath() const { return Path.string(); }
96
97 FORCEINLINE std::filesystem::path GetParentPath() const
98 {
99 return Path.parent_path();
100 }
101
102 FORCEINLINE void SetPath(const std::string& InFilePath)
103 {
104 Path = InFilePath;
105 }
106
107 private:
108 std::filesystem::path Path{};
109 std::string Name{};
110 };
111}
112#endif
Definition Asset.h:11