From: Terri00 Date: Sat, 16 Mar 2019 23:13:03 +0000 (+0000) Subject: installer X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=de6d6886b3d5d2673bd8aff7d86257a676cc3d2b;p=tar-legacy.git installer --- diff --git a/.gitignore b/.gitignore index 6ab7375..c204c51 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ MCDV_Lib/ MCDV_Lib_Sharp/ MCDV_Processor/ MCDV_Web/ +installer/ # User-specific files *.suo @@ -38,6 +39,7 @@ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ +[Dd]eploy/ # Visual Studio 2015 cache/options directory .vs/ diff --git a/AutoRadar_installer/AutoRadar_installer.vcxproj b/AutoRadar_installer/AutoRadar_installer.vcxproj new file mode 100644 index 0000000..4952a2b --- /dev/null +++ b/AutoRadar_installer/AutoRadar_installer.vcxproj @@ -0,0 +1,132 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA} + AutoRadarinstaller + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)\installer\$(Configuration)\ + + + $(SolutionDir)\installer\$(Configuration)\ + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutoRadar_installer/AutoRadar_installer.vcxproj.filters b/AutoRadar_installer/AutoRadar_installer.vcxproj.filters new file mode 100644 index 0000000..7ef2532 --- /dev/null +++ b/AutoRadar_installer/AutoRadar_installer.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/AutoRadar_installer/ConColor.h b/AutoRadar_installer/ConColor.h new file mode 100644 index 0000000..ca97e0f --- /dev/null +++ b/AutoRadar_installer/ConColor.h @@ -0,0 +1,42 @@ +#pragma once +#include +#include + +HANDLE hConsole; +uint16_t consoleColorDefault; + +namespace cc { + + void setup() { + hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO info; + GetConsoleScreenBufferInfo(hConsole, &info); + + consoleColorDefault = info.wAttributes; + } + + void reset() { + SetConsoleTextAttribute(hConsole, consoleColorDefault); + } + + void error() { + SetConsoleTextAttribute(hConsole, 12); + } + + void warning() { + SetConsoleTextAttribute(hConsole, 14); + } + + void info() { + SetConsoleTextAttribute(hConsole, 8); + } + + void success() { + SetConsoleTextAttribute(hConsole, 10); + } + + void fancy() { + SetConsoleTextAttribute(hConsole, 13); + } +} \ No newline at end of file diff --git a/AutoRadar_installer/FileSystemHelper.h b/AutoRadar_installer/FileSystemHelper.h new file mode 100644 index 0000000..951e62e --- /dev/null +++ b/AutoRadar_installer/FileSystemHelper.h @@ -0,0 +1,75 @@ +#include +#include +#include + +namespace fs +{ + std::vector getFilesInDirectory(std::string folder) { + std::vector names; + std::string search_path = folder + "/*.*"; + WIN32_FIND_DATA fd; + HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd); + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + names.push_back(folder + "\\" + fd.cFileName); + } + } while (::FindNextFile(hFind, &fd)); + ::FindClose(hFind); + } + for (auto && s : names) s = s.substr(s.size()); + + return names; + } + + std::vector getFilesInDirectoryRecursive(std::string folder, std::vector* vec = NULL) { + std::vector* v = vec; + + std::vector names; + if (v == NULL) // First iteration + v = &names; + + std::string search_path = folder + "/*.*"; + WIN32_FIND_DATA fd; + HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd); + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + v->push_back(folder + "\\" + fd.cFileName); + } + else { + if ((std::string(fd.cFileName) != ".") && (std::string(fd.cFileName) != "..")) + getFilesInDirectoryRecursive(folder + "\\" + fd.cFileName, v); + } + } while (::FindNextFile(hFind, &fd)); + ::FindClose(hFind); + } + + for (auto && s : names) s = s.substr(folder.size()); + + return *v; + } + + void copyFile(std::string src, std::string dst) { + std::ifstream _src(src, std::ios::binary); + std::ofstream _dst(dst, std::ios::binary); + + _dst << _src.rdbuf(); + } + + + bool dirExists(const std::string& dirName_in) { + DWORD ftyp = GetFileAttributesA(dirName_in.c_str()); + if (ftyp == INVALID_FILE_ATTRIBUTES) + return false; //something is wrong with your path! + + if (ftyp & FILE_ATTRIBUTE_DIRECTORY) + return true; // this is a directory! + + return false; // this is not a directory! + } + + std::string getDirName(std::string f) { + return f.substr(0, f.size() - split(sutil::ReplaceAll(f, "/", "\\"), '\\').back().size()); + } +} \ No newline at end of file diff --git a/AutoRadar_installer/main.cpp b/AutoRadar_installer/main.cpp new file mode 100644 index 0000000..12ac9ba --- /dev/null +++ b/AutoRadar_installer/main.cpp @@ -0,0 +1,224 @@ +#include "../MCDV/vdf.hpp" +#include "../MCDV/wc.hpp" +#include "../MCDV/util.h" + +#include +#include +#include +#include + +#include "ConColor.h" + +#include "FileSystemHelper.h" + +std::string steam_install_path = "C:\\Program Files (x86)\\Steam\\"; +std::string csgo_sdk_bin_path = ""; + +int exit() { + cc::reset(); + system("PAUSE"); + return -1; +} + +int main(){ + cc::setup(); + + /* Load install configuration */ + std::ifstream ifs_vinfo("versioninfo.vdf"); + if (!ifs_vinfo) { + cc::error(); + std::cout << "versioninfo.vdf not found!!!" << std::endl; + return exit(); + } + + cc::info(); + + std::string vinfo_str((std::istreambuf_iterator(ifs_vinfo)), std::istreambuf_iterator()); + kv::FileData vinfo(vinfo_str); + kv::DataBlock vinfodata = vinfo.headNode.SubBlocks[0]; + + cc::fancy(); std::cout << "Installing version: " << vinfodata.Values["version"] << "\n"; + +#pragma region sdk_detect + /* Get steam installation path */ + + cc::info(); std::cout << "Getting steam installation path from windows registry\n"; + + HKEY hKey = NULL; + char buffer[1024]; + + bool regReadSuccess = true; + + if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Valve\\Steam", NULL, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS){ + DWORD size; + if (RegQueryValueEx(hKey, "SteamPath", NULL, NULL, (LPBYTE)buffer, &size) == ERROR_SUCCESS){ + steam_install_path = buffer; + steam_install_path += "\\"; + } + else regReadSuccess = false; + } + else regReadSuccess = false; + + RegCloseKey(hKey); + + if (!regReadSuccess) { + cc::warning(); + std::cout << "Failed to read registry key: 'Software\\Valve\\Steam\\SteamPath'\nDefaulting to C:\\Program Files (x86)\\Steam\\ installation...\n"; + } + + cc::info(); + std::cout << "Reading steam library folders\n"; + + /* Read library folders file */ + + std::vector libraryFolders; + libraryFolders.push_back(steam_install_path + "steammapps\\common\\"); + + std::ifstream ifs(steam_install_path + "steamapps\\libraryfolders.vdf"); + if (!ifs) { + std::cout << "Libraryfolders.vdf not found. Skipping search...\n" << std::endl; + } + else { + std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + kv::FileData libFolders(str); + + kv::DataBlock* libFoldersDB = libFolders.headNode.GetFirstByName("\"LibraryFolders\""); + + if (libFoldersDB != NULL) { + int index = 0; + while (libFoldersDB->Values.count(std::to_string(++index))) libraryFolders.push_back(libFoldersDB->Values[std::to_string(index)] + "\\steamapps\\common\\"); + } + } + + if (libraryFolders.size() == 0) std::cout << "No library folders found, defaulting to steamapps common folder...\n"; + + /* Scan for csgo sdk installations */ + + std::cout << "Scanning for SDK installation\n"; + + for (auto && folder : libraryFolders) { + if (_access_s((folder + "Counter-Strike Global Offensive\\bin\\SDKLauncher.exe").c_str(), 0) == 0) { + csgo_sdk_bin_path = folder + "Counter-Strike Global Offensive\\bin\\"; + } + } + + if (csgo_sdk_bin_path == "") { + cc::error(); + std::cout << "Failed to find CS:GO SDK bin.\n"; + return exit(); + } + +#pragma endregion + + /* Start doing the heavy work */ + std::cout << "Copying files\n________________________________________________________\n\n"; + + // Copy folders + for (auto && folder : vinfodata.GetAllByName("folder")){ + std::string source_folder = kv::tryGetStringValue(folder.Values, "path"); + std::string target_folder = kv::tryGetStringValue(folder.Values, "target"); + + if ((source_folder == "") || (target_folder == "")) { + cc::warning(); std::cout << "Missing source/destination paths. Skipping...\n"; + continue; + } + + cc::info(); + std::cout << "Copying folder: " << source_folder << "\n"; + + source_folder = source_folder + "\\"; + target_folder = csgo_sdk_bin_path + target_folder + "\\"; + + std::vector files = fs::getFilesInDirectoryRecursive(source_folder); + + for (auto && f : files) { + std::string fDstFolder = target_folder + fs::getDirName(f); + + if (_access_s(fDstFolder.c_str(), 0)) { + std::cout << "mkdr " << fs::getDirName(f) << "\n"; + CreateDirectory(fDstFolder.c_str(), NULL); + } + + std::cout << "copy " << f << "\n"; + + fs::copyFile(source_folder + f, target_folder + f); + } + } + + std::cout << "\n"; + + // Install command sequences + std::cout << "Installing command sequences\n________________________________________________________\n\n"; + + for (auto && seqH : vinfodata.GetAllByName("CommandSequenceFile")) { + std::string target_file = kv::tryGetStringValue(seqH.Values, "target"); + + if (target_file == "") { + cc::warning(); std::cout << "Missing target file. Skipping CommandSeq...\n"; + continue; + } + + cc::info(); + + target_file = csgo_sdk_bin_path + target_file; + + fs::copyFile(target_file, target_file + ".bak"); + + wc::filedata WcFile(target_file); + + std::cout << "Writing to: " << kv::tryGetStringValue(seqH.Values, "target") << "\n"; + + for (auto && seqS : seqH.GetAllByName("Sequence")) { + std::cout << "Installing sequence: " << kv::tryGetStringValue(seqS.Values, "name", "error-name") << "\n"; + std::string name = kv::tryGetStringValue(seqS.Values, "name", "error-name"); + + for (auto && seq : WcFile.sequences) { + if (strstr(seq.name, name.c_str()) != NULL) { + seq.write_enable = false; + } + } + + wc::Sequence seq_new = wc::Sequence(); + strcpy_s(seq_new.name, name.c_str()); + + for (auto && cmd : seqS.GetAllByName("Command")) + { + wc::Command command_build = wc::Command(); + command_build.is_enabled = kv::tryGetValue(cmd.Values, "is_enabled", 0); + command_build.special = kv::tryGetValue(cmd.Values, "special", 0); + command_build.is_long_filename = kv::tryGetValue(cmd.Values, "is_long_filename", 0); + command_build.ensure_check = kv::tryGetValue(cmd.Values, "ensure_check", 0); + command_build.use_proc_win = kv::tryGetValue(cmd.Values, "use_proc_win", 0); + command_build.no_wait = kv::tryGetValue(cmd.Values, "no_wait", 0);; + + std::string executable = kv::tryGetStringValue(cmd.Values, "executable", "error-executable"); + + strcpy_s(command_build.executable, executable.c_str()); + + std::string args = kv::tryGetStringValue(cmd.Values, "args", "error-args"); + strcpy_s(command_build.args, args.c_str()); + + seq_new.commands.push_back(command_build); + } + + WcFile.sequences.push_back(seq_new); + } + + WcFile.serialize(target_file); + } + + // Install custom entities + + cc::success(); std::cout << "Completed setup!\n"; + + /* Small wait to auto close */ + for (int i = 10; i > 0; i--) { + cc::info(); + std::cout << "Closing in " << i << " seconds...\r"; + Sleep(1000); + } + + cc::reset(); + std::cout << "\n"; + return 0; +} \ No newline at end of file diff --git a/MCDV.sln b/MCDV.sln index b1be4ed..90d2097 100644 --- a/MCDV.sln +++ b/MCDV.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27004.2006 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MCDV", "MCDV\MCDV.vcxproj", "{3F5631FE-0F0C-4285-B301-66DA219121EC}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AutoRadar", "MCDV\MCDV.vcxproj", "{3F5631FE-0F0C-4285-B301-66DA219121EC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AutoRadar_installer", "AutoRadar_installer\AutoRadar_installer.vcxproj", "{D73B6BD7-47B5-4426-BC6B-26B69F47CACA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -25,6 +27,16 @@ Global {3F5631FE-0F0C-4285-B301-66DA219121EC}.Release|x64.Build.0 = Release|x64 {3F5631FE-0F0C-4285-B301-66DA219121EC}.Release|x86.ActiveCfg = Release|Win32 {3F5631FE-0F0C-4285-B301-66DA219121EC}.Release|x86.Build.0 = Release|Win32 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Debug|x64.ActiveCfg = Debug|x64 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Debug|x64.Build.0 = Debug|x64 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Debug|x86.ActiveCfg = Debug|Win32 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Debug|x86.Build.0 = Debug|Win32 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Release|Any CPU.ActiveCfg = Release|Win32 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Release|x64.ActiveCfg = Release|x64 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Release|x64.Build.0 = Release|x64 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Release|x86.ActiveCfg = Release|Win32 + {D73B6BD7-47B5-4426-BC6B-26B69F47CACA}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MCDV/CmdSeq.wc b/MCDV/CmdSeq.wc index 1129ba3..0279d45 100644 Binary files a/MCDV/CmdSeq.wc and b/MCDV/CmdSeq.wc differ diff --git a/MCDV/main2.cpp b/MCDV/main2.cpp index 30d7720..a944c1f 100644 --- a/MCDV/main2.cpp +++ b/MCDV/main2.cpp @@ -6,12 +6,33 @@ int main() { - wc::filedata fileData("sample_stuff/CmdSeq.wc"); + wc::filedata fileData("CmdSeq.wc"); + + for (auto && seq : fileData.sequences) { + if (strstr(seq.name, "[TAR] Generate Radar") != NULL){ + seq.write_enable = false; + } + } wc::Sequence seq_new = wc::Sequence(); - char name_new[128] = "Testeroonie BAP"; + char name_new[128] = "[TAR] Generate Radar"; memcpy(&seq_new.name, &name_new, 128); + wc::Command command_build = wc::Command(); + command_build.is_enabled = 1; + command_build.special = 0; + command_build.is_long_filename = 0; + command_build.ensure_check = 0; + command_build.use_proc_win = 0; + command_build.no_wait = 0; + + char executable[260] = "$exedir\\bin\\tar\\AutoRadar.exe"; + memcpy(&command_build.executable, &executable, 260); + + char args[260] = "-g $gamedir $path\\$file"; + memcpy(&command_build.args, &args, 260); + + seq_new.commands.push_back(command_build); fileData.sequences.push_back(seq_new); fileData.serialize("CmdSeq.wc"); diff --git a/MCDV/sample_stuff/de_tavr_test.vmx b/MCDV/sample_stuff/de_tavr_test.vmx index c388348..452afc2 100644 --- a/MCDV/sample_stuff/de_tavr_test.vmx +++ b/MCDV/sample_stuff/de_tavr_test.vmx @@ -2,7 +2,7 @@ versioninfo { "editorversion" "400" "editorbuild" "8075" - "mapversion" "53" + "mapversion" "54" "formatversion" "100" "prefab" "0" } @@ -44,7 +44,7 @@ viewsettings world { "id" "1" - "mapversion" "53" + "mapversion" "54" "classname" "worldspawn" "detailmaterial" "detail/detailsprites" "detailvbsp" "detail.vbsp" diff --git a/MCDV/vdf.hpp b/MCDV/vdf.hpp index 527aa2b..1053001 100644 --- a/MCDV/vdf.hpp +++ b/MCDV/vdf.hpp @@ -19,7 +19,12 @@ namespace kv template T tryGetValue(std::map map, const char* key, T defaultValue) { if (!map.count(key)) return defaultValue; - return static_cast(::atof(key)); + return static_cast(::atof(map[key].c_str())); + } + + std::string tryGetStringValue(std::map map, const char* key, std::string defaultValue = "") { + if (!map.count(key)) return defaultValue; + return map[key]; } class DataBlock diff --git a/MCDV/wc.hpp b/MCDV/wc.hpp index c14591a..2dfbafa 100644 --- a/MCDV/wc.hpp +++ b/MCDV/wc.hpp @@ -33,6 +33,7 @@ namespace wc { char name[128]; std::vector commands; + bool write_enable = true; }; struct Header { @@ -92,12 +93,18 @@ namespace wc // Write header Header header = Header(); - header.seq_count = sequences.size(); + + int count = sequences.size(); + for (auto && seq : this->sequences) if (!seq.write_enable) count--; + + header.seq_count = count; writer.write((char*)&header, sizeof(header)); // Write Sequences for (auto && sequence : this->sequences){ + if (!sequence.write_enable) continue; + writer.write((char*)&sequence.name, 128); uint32_t cmdCount = sequence.commands.size();