3 #include <Strings/components/logger/logger.h>
4 #include <Strings/components/utils/io/io.h>
5 #include <Strings/components/utils/string/string.h>
6 #include <Strings/components/utils/list/list.h>
7 #include <Strings/components/3rdparty/rapidxml/rapidxml.hpp>
8 #include <HEKGuerilla/components/projects/projects.h>
10 #include "../ToolCommand.hpp"
11 #include "../console.h"
14 #ifdef TOOL_LIB_EXPORTS
15 #define TOOL_LIB_API __declspec(dllexport)
17 #define TOOL_LIB_API __declspec(dllimport)
28 std::string include_path_placeholders[4] = {
29 "{$__INCLUDE_DIRS_DW32__}",
30 "{$__INCLUDE_DIRS_DW64__}",
31 "{$__INCLUDE_DIRS_RW32__}",
32 "{$__INCLUDE_DIRS_RW64__}"
35 std::string lib_path_placeholders[4] = {
36 "{$__LIBRARY_DIRS_DW32__}",
37 "{$__LIBRARY_DIRS_DW64__}",
38 "{$__LIBRARY_DIRS_RW32__}",
39 "{$__LIBRARY_DIRS_RW64__}"
42 std::string engine_lib_dir_suffixes[4] = {
45 "cache release/Win32",
49 std::string default_deps =
"blam.lib;Strings.lib";
50 std::string default_deps_placeholder =
"{$__DEPS__}";
52 std::string hek_root_placeholder =
"{$__HEK_ROOT__}";
55 bool overwrite =
false;
57 std::vector<std::string> PreprocessArgs(std::vector<std::string> args)
59 std::vector<std::string> processed_args = std::vector<std::string>();
61 for (
int i = 0; i < args.size(); i++)
63 if (args[i] ==
"-verbose")
67 else if (args[i] ==
"-overwrite")
73 processed_args.push_back(args[i]);
77 return processed_args;
83 command =
"generate-script-project";
84 syntax =
"generate-script-project [-verbose] [-overwrite]";
85 description =
"generates a preconfigured visual studio project for the current project";
88 int execute(std::vector<std::string> args)
90 args = PreprocessArgs(args);
93 std::string project_filename = BlamStrings::Utils::IO::GetFileNameWithoutExtension(project_root) +
".blam";
97 project_filename = args[0];
100 BlamProject* project_info = Guerilla::Projects::LoadProject(project_root + project_filename);
102 if (!project_info->IsLoaded())
104 BlamStrings::Logger::LogEvent(
"failed to create stub project: could not load project info (tried to "
105 "read from file path: " + project_root + project_filename +
")", WSV_ERROR);
107 if (args.size() == 0)
109 BlamStrings::Logger::LogEvent(
"project path was assumed from directory path - if your .blam file "
110 "has a different name, use " + syntax +
" to specify the filename", WSV_WARNING);
117 std::string script_project_base_dir =
"./content/blam/default_script_project/";
121 std::string source_sln_path = script_project_base_dir +
"BLAM_GAME_TITLE.sln";
122 std::string destination_sln_path = project_root + project_info->project_name +
".sln";
124 if (!CopyTextFile(source_sln_path, destination_sln_path,
"visual studio solution"))
133 std::string source_path = script_project_base_dir +
"BLAM_GAME_TITLE.vcxproj.user";
134 std::string destination_path = project_root + project_info->project_name +
".vcxproj.user";
136 if (!CopyTextFile(source_path, destination_path,
".vcxproj.user"))
143 std::string destination_vcxproj_path = project_root + project_info->project_name +
".vcxproj";
144 std::string hek_root = BlamStrings::Utils::IO::GetApplicationDir();
146 if (!BlamStrings::Utils::IO::FileExists(destination_vcxproj_path) || overwrite)
148 std::string vcxproj_file_contents = BlamStrings::Utils::IO::GetFileContentsAsString(script_project_base_dir +
"BLAM_GAME_TITLE.vcxproj");
150 for (
int i = 0; i < 4; i++)
152 std::string engine_dep_path = project_info->GetEngineDependenciesPath() +
"/" + engine_lib_dir_suffixes[i] +
"/";
153 std::string engine_include_path = project_info->GetEngineDependenciesPath() +
"/include/";
155 vcxproj_file_contents = str_replace(vcxproj_file_contents, include_path_placeholders[i], engine_include_path);
156 vcxproj_file_contents = str_replace(vcxproj_file_contents, lib_path_placeholders[i], engine_dep_path +
"/lib");
158 vcxproj_file_contents = str_replace(vcxproj_file_contents, default_deps_placeholder, default_deps);
159 vcxproj_file_contents = str_replace(vcxproj_file_contents, hek_root_placeholder, hek_root);
162 if (!BlamStrings::Utils::IO::CreateNewFile(destination_vcxproj_path, vcxproj_file_contents))
164 BlamStrings::Logger::LogEvent(
"failed to create new vcxproj: CreateNewFile returned false", WSV_ERROR);
170 BlamStrings::Logger::LogEvent(
"not copying default vcxproj: file already exists", WSV_WARNING);
171 BlamStrings::Logger::LogEvent(
"hint: use -overwrite argument to overwrite your current .vcxproj if "
172 "desired, but this will cause data loss!", WSV_WARNING);
175 BlamStrings::Logger::LogEvent(
"script project created");
181 bool CopyTextFile(std::string source, std::string destination, std::string debug_file_title)
183 if (!BlamStrings::Utils::IO::FileExists(destination) || overwrite)
185 std::string contents = BlamStrings::Utils::IO::GetFileContentsAsString(source);
187 if (!BlamStrings::Utils::IO::CreateNewFile(destination, contents))
189 BlamStrings::Logger::LogEvent(
"failed to create new " + debug_file_title +
": CreateNewFile returned false", WSV_ERROR);
195 BlamStrings::Logger::LogEvent(
"not copying default " + debug_file_title +
": file already exists", WSV_WARNING);
196 BlamStrings::Logger::LogEvent(
"hint: use -overwrite argument to overwrite the existing file if "
197 "desired, but this will cause data loss!", WSV_WARNING);