2017-10-02 21:24:00 +00:00
|
|
|
/*************************************************************************/
|
2018-11-08 00:05:19 +00:00
|
|
|
/* dotnet_solution.cpp */
|
2017-10-02 21:24:00 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2019-01-01 11:53:14 +00:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-10-02 21:24:00 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
#include "dotnet_solution.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/file_access.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
#include "../utils/path_utils.h"
|
|
|
|
#include "../utils/string_utils.h"
|
|
|
|
#include "csharp_project.h"
|
|
|
|
|
|
|
|
#define SOLUTION_TEMPLATE \
|
|
|
|
"Microsoft Visual Studio Solution File, Format Version 12.00\n" \
|
|
|
|
"# Visual Studio 2012\n" \
|
|
|
|
"%0\n" \
|
|
|
|
"Global\n" \
|
|
|
|
"\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n" \
|
|
|
|
"%1\n" \
|
|
|
|
"\tEndGlobalSection\n" \
|
|
|
|
"\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n" \
|
|
|
|
"%2\n" \
|
|
|
|
"\tEndGlobalSection\n" \
|
|
|
|
"EndGlobal\n"
|
|
|
|
|
|
|
|
#define PROJECT_DECLARATION "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"%0\", \"%1\", \"{%2}\"\nEndProject"
|
|
|
|
|
2018-10-22 17:27:41 +00:00
|
|
|
#define SOLUTION_PLATFORMS_CONFIG "\t%0|Any CPU = %0|Any CPU"
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
#define PROJECT_PLATFORMS_CONFIG \
|
|
|
|
"\t\t{%0}.%1|Any CPU.ActiveCfg = %1|Any CPU\n" \
|
|
|
|
"\t\t{%0}.%1|Any CPU.Build.0 = %1|Any CPU"
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
void DotNetSolution::add_new_project(const String &p_name, const ProjectInfo &p_project_info) {
|
|
|
|
projects[p_name] = p_project_info;
|
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
bool DotNetSolution::has_project(const String &p_name) const {
|
|
|
|
return projects.find(p_name) != NULL;
|
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
const DotNetSolution::ProjectInfo &DotNetSolution::get_project_info(const String &p_name) const {
|
|
|
|
return projects[p_name];
|
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
bool DotNetSolution::remove_project(const String &p_name) {
|
|
|
|
return projects.erase(p_name);
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
Error DotNetSolution::save() {
|
2017-10-02 21:24:00 +00:00
|
|
|
bool dir_exists = DirAccess::exists(path);
|
|
|
|
ERR_EXPLAIN("The directory does not exist.");
|
2018-11-08 00:05:19 +00:00
|
|
|
ERR_FAIL_COND_V(!dir_exists, ERR_FILE_NOT_FOUND);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
String projs_decl;
|
|
|
|
String sln_platform_cfg;
|
|
|
|
String proj_platform_cfg;
|
|
|
|
|
|
|
|
for (Map<String, ProjectInfo>::Element *E = projects.front(); E; E = E->next()) {
|
|
|
|
const String &name = E->key();
|
2018-11-08 00:05:19 +00:00
|
|
|
const ProjectInfo &proj_info = E->value();
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
bool is_front = E == projects.front();
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
if (!is_front)
|
|
|
|
projs_decl += "\n";
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
projs_decl += sformat(PROJECT_DECLARATION, name, proj_info.relpath.replace("/", "\\"), proj_info.guid);
|
|
|
|
|
|
|
|
for (int i = 0; i < proj_info.configs.size(); i++) {
|
|
|
|
const String &config = proj_info.configs[i];
|
|
|
|
|
|
|
|
if (i != 0 || !is_front) {
|
2017-10-02 21:24:00 +00:00
|
|
|
sln_platform_cfg += "\n";
|
|
|
|
proj_platform_cfg += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sln_platform_cfg += sformat(SOLUTION_PLATFORMS_CONFIG, config);
|
2018-11-08 00:05:19 +00:00
|
|
|
proj_platform_cfg += sformat(PROJECT_PLATFORMS_CONFIG, proj_info.guid, config);
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String content = sformat(SOLUTION_TEMPLATE, projs_decl, sln_platform_cfg, proj_platform_cfg);
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
FileAccess *file = FileAccess::open(path_join(path, name + ".sln"), FileAccess::WRITE);
|
|
|
|
ERR_FAIL_NULL_V(file, ERR_FILE_CANT_WRITE);
|
2017-10-02 21:24:00 +00:00
|
|
|
file->store_string(content);
|
|
|
|
file->close();
|
2018-11-08 00:05:19 +00:00
|
|
|
memdelete(file);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
bool DotNetSolution::set_path(const String &p_existing_path) {
|
2017-10-02 21:24:00 +00:00
|
|
|
if (p_existing_path.is_abs_path()) {
|
|
|
|
path = p_existing_path;
|
|
|
|
} else {
|
|
|
|
String abspath;
|
|
|
|
if (!rel_path_to_abs(p_existing_path, abspath))
|
|
|
|
return false;
|
|
|
|
path = abspath;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
String DotNetSolution::get_path() {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
DotNetSolution::DotNetSolution(const String &p_name) {
|
2017-10-02 21:24:00 +00:00
|
|
|
name = p_name;
|
|
|
|
}
|