-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileoperations.cpp
87 lines (74 loc) · 2.1 KB
/
fileoperations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "fileoperations.h"
#include <fstream>
ttvfs::VFSHelper vfs;
void init_fileio()
{
// Make the VFS usable
vfs.Prepare();
}
void shutdown_fileio()
{
}
std::string to_lowercase(std::string s)
{
std::string ret;
for(int i = 0; i < s.length(); i++)
ret.push_back(tolower(s[i]));
return ret;
}
std::deque<std::string> get_files_from_dir_rec(std::string sFolderName)
{
std::set<std::string> lFileFilters;
return get_files_from_dir_rec(sFolderName, lFileFilters);
}
std::deque<std::string> get_files_from_dir_rec(std::string sFolderName, std::set<std::string> lFileFilters)
{
ttvfs::StringList lFilenames;
//Recursively get the filenames of all files contained within this folder
ttvfs::StringList lFolders;
ttvfs::GetDirList(sFolderName.c_str(), lFolders, -1);
if(!lFolders.empty())
{
for(ttvfs::StringList::iterator i = lFolders.begin(); i != lFolders.end(); i++)
ttvfs::GetFileList(i->c_str(), lFilenames);
}
if(!lFileFilters.empty() && !lFilenames.empty())
{
for(ttvfs::StringList::iterator i = lFilenames.begin(); i != lFilenames.end(); i++) //TODO: Can hang here quite a while...
{
size_t pos = i->find_last_of('.');
if(pos != std::string::npos && pos != i->length()-1)
{
std::string substr = i->substr(pos+1); //Get filename extension of song
if(!lFileFilters.count(to_lowercase(substr)))
i->clear(); //Remove from list if it doesn't pass our filter
}
else
i->clear();
}
}
return lFilenames;
}
std::set<std::string> get_filetypes_supported()
{
std::set<std::string> ret;
ret.insert("mp3");
ret.insert("wma");
ret.insert("ogg");
ret.insert("flac");
ret.insert("opus");
ret.insert("m4a");
ret.insert("wav");
ret.insert("ay");
ret.insert("gbs");
ret.insert("gym");
ret.insert("hes");
ret.insert("kss");
ret.insert("nsf");
ret.insert("nsfe");
ret.insert("sap");
ret.insert("spc");
ret.insert("vgm");
ret.insert("vgz");
return ret;
}