TDME2  1.9.200
createrc-main.cpp
Go to the documentation of this file.
1 #include <string>
2 
3 #include <tdme/tdme.h>
5 #include <tdme/engine/Version.h>
12 
13 using std::string;
14 
23 
24 int main(int argc, char** argv)
25 {
26  Console::println(string("createrc ") + Version::getVersion());
27  Console::println(Version::getCopyright());
28  Console::println();
29 
30  if (argc != 4) {
31  Console::println("Usage: createrc path_to_rc file path_to_generated_rc");
32  Application::exit(Application::EXITCODE_FAILURE);
33  }
34 
35  //
36  string rcInFileName = argv[1];
37  string fileName = argv[2];
38  string rcOutFileName = argv[3];
39 
40  //
41  try {
42  auto rc = FileSystem::getInstance()->getContentAsString(
43  FileSystem::getInstance()->getPathName(rcInFileName),
44  FileSystem::getInstance()->getFileName(rcInFileName)
45  );
46 
47  //
48  if (StringTools::endsWith(fileName, ".exe") == true) {
49  auto executable = StringTools::substring(fileName, fileName.rfind('/') + 1, fileName.find(".exe"));
50  auto executableLowerCase = StringTools::toLowerCase(executable);
51  rc = StringTools::replace(rc, "{__EXECUTABLE__}", executable);
52  if (FileSystem::getInstance()->exists("resources/platforms/win32/" + executableLowerCase + "-icon.ico") == true) {
53  rc = StringTools::replace(rc, "{__ICON__}", "resources/platforms/win32/" + executableLowerCase + "-icon.ico");
54  } else {
55  rc = StringTools::replace(rc, "{__ICON__}", "resources/platforms/win32/default-icon.ico");
56  }
57  } else
58  if (StringTools::endsWith(fileName, ".dll") == true) {
59  auto library = StringTools::substring(fileName, fileName.rfind('/') + 1, fileName.find(".dll"));
60  rc = StringTools::replace(rc, "{__LIBRARY__}", library);
61  }
62 
63  //
64  FileSystem::getInstance()->setContentFromString(
65  FileSystem::getInstance()->getPathName(rcOutFileName),
66  FileSystem::getInstance()->getFileName(rcOutFileName),
67  rc
68  );
69 
70  Console::println(rc);
71  } catch (Exception& exception) {
72  Console::println(string() + "An error occurred: " + exception.what());
73  }
74 
75  //
76  Application::exit(Application::EXITCODE_SUCCESS);
77 }
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
File system singleton class.
Definition: FileSystem.h:17
Console class.
Definition: Console.h:29
String tokenizer class.
String tools class.
Definition: StringTools.h:22
int main(int argc, char **argv)
std::exception Exception
Exception base class.
Definition: Exception.h:18