From 23aad83f510a003e6a76175f12d279156743f77b Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Tue, 9 Aug 2022 17:13:25 +0800 Subject: [PATCH] Update --- .vscode/settings.json | 5 +++ src/download_temp_file.cpp | 40 ++++++++++++++++++++++++ src/draft.cpp | 63 -------------------------------------- src/ghost_installer.cpp | 43 ++++++++++++++++++++++++++ src/my-gists | 2 +- 5 files changed, 89 insertions(+), 64 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/download_temp_file.cpp delete mode 100644 src/draft.cpp create mode 100644 src/ghost_installer.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..deb3f2f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "xstring": "cpp" + } +} \ No newline at end of file diff --git a/src/download_temp_file.cpp b/src/download_temp_file.cpp new file mode 100644 index 0000000..f022b4c --- /dev/null +++ b/src/download_temp_file.cpp @@ -0,0 +1,40 @@ +#include +#include +std::wstring download_temp_file(const std::wstring& url, const std::wstring& file_suffix) { + //get temp path + static wchar_t temp_path[MAX_PATH]; + static bool temp_path_initer=(bool)GetTempPath(MAX_PATH, temp_path); + //generate a temporary file name + std::wstring temp_file_name; + temp_file_name.reserve(MAX_PATH); + GetTempFileNameW(temp_path, L"ghi", 0, temp_file_name.data()); + temp_file_name.resize(wcslen(temp_file_name.data())); + //append file suffix + temp_file_name+=file_suffix; + //download file + HINTERNET hInternet=InternetOpenW(L"ghost_installer", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); + if(hInternet==NULL) { + throw std::runtime_error("InternetOpenW failed"); + } + HINTERNET hFile=InternetOpenUrlW(hInternet, url.c_str(), NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0); + if(hFile==NULL) { + InternetCloseHandle(hInternet); + throw std::runtime_error("InternetOpenUrlW failed"); + } + HANDLE hFileHandle=CreateFileW(temp_file_name.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); + if(hFileHandle==INVALID_HANDLE_VALUE) { + InternetCloseHandle(hFile); + InternetCloseHandle(hInternet); + throw std::runtime_error("CreateFileW failed"); + } + DWORD dwBytesRead=0; + DWORD dwBytesWritten=0; + unsigned char buffer[1024]; + while(InternetReadFile(hFile, buffer, 1024, &dwBytesRead) && dwBytesRead>0) { + WriteFile(hFileHandle, buffer, dwBytesRead, &dwBytesWritten, NULL); + } + InternetCloseHandle(hFile); + InternetCloseHandle(hInternet); + CloseHandle(hFileHandle); + return temp_file_name; +} diff --git a/src/draft.cpp b/src/draft.cpp deleted file mode 100644 index fde1387..0000000 --- a/src/draft.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include "my-gists/ukagaka/SSPpath.hpp" - -std::wstring download_temp_file(const std::wstring& url, const std::wstring& file_suffix) { - //get temp path - static wchar_t temp_path[MAX_PATH]; - static bool temp_path_initer=(bool)GetTempPath(MAX_PATH, temp_path); - //generate a temporary file name - std::wstring temp_file_name; - temp_file_name.reserve(MAX_PATH); - GetTempFileNameW(temp_path, L"ghi", 0, temp_file_name.data()); - temp_file_name.resize(wcslen(temp_file_name.data())); - //append file suffix - temp_file_name+=file_suffix; - //download file - HINTERNET hInternet=InternetOpenW(L"ghost_installer", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); - if(hInternet==NULL) { - throw std::runtime_error("InternetOpenW failed"); - } - HINTERNET hFile=InternetOpenUrlW(hInternet, url.c_str(), NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0); - if(hFile==NULL) { - InternetCloseHandle(hInternet); - throw std::runtime_error("InternetOpenUrlW failed"); - } - HANDLE hFileHandle=CreateFileW(temp_file_name.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); - if(hFileHandle==INVALID_HANDLE_VALUE) { - InternetCloseHandle(hFile); - InternetCloseHandle(hInternet); - throw std::runtime_error("CreateFileW failed"); - } - DWORD dwBytesRead=0; - DWORD dwBytesWritten=0; - unsigned char buffer[1024]; - while(InternetReadFile(hFile, buffer, 1024, &dwBytesRead) && dwBytesRead>0) { - WriteFile(hFileHandle, buffer, dwBytesRead, &dwBytesWritten, NULL); - } - CloseHandle(hFileHandle); - InternetCloseHandle(hFile); - InternetCloseHandle(hInternet); - return temp_file_name; -} -std::wstring get_ghost_url(){ - //TODO get ghost url from self file -} - -int main() { - if(IsSSPinstalled()) { - try{ - auto nar_file=download_temp_file(get_ghost_url(), L".nar"); - auto SSPpath=GetSSPpath(); - //TODO install ghost - } - } - else{ - //TODO download and install SSP - //get language id - //show install path dialog - //install SSP(download zip & extract) - //chose&install language pack & ghost for starter - //install ghost - } - return 0; -} diff --git a/src/ghost_installer.cpp b/src/ghost_installer.cpp new file mode 100644 index 0000000..5ad8d38 --- /dev/null +++ b/src/ghost_installer.cpp @@ -0,0 +1,43 @@ +#include +#include +#include "my-gists/ukagaka/SSP_Runner.hpp" + +std::wstring download_temp_file(const std::wstring& url, const std::wstring& file_suffix); +std::wstring get_ghost_url(){ + #ifdef _DEBUG + return L"https://github.com/Taromati2/Taromati2/releases/download/balloon/wiz.nar"; + #else + //TODO get ghost url from self file + #endif +} + +int main() { + SSP_Runner SSP; + if(SSP.IsInstalled()) { + try{ + auto nar_file=download_temp_file(get_ghost_url(), L".nar"); + SSP.install_nar(nar_file); + } + catch(const std::exception& e) { + MessageBoxA(NULL, e.what(), "Error", MB_OK); + } + } + else{ + //download and install SSP + auto ssp_file=download_temp_file(L"http://ssp.shillest.net/archive/redir.cgi?stable&full", L".exe"); + EXE_Runner SSP_EXE(ssp_file); + //Get the program (x86) directory for installation + std::wstring program_dir; + program_dir.reserve(MAX_PATH); + SHGetSpecialFolderPath(NULL, program_dir.data(), CSIDL_PROGRAM_FILESX86, FALSE); + program_dir.resize(wcslen(program_dir.data())); + program_dir+=L"\\SSP"; + SSP_EXE(L"-o\""+program_dir+L"\""); + //get language id + //show install path dialog + //install SSP(download zip & extract) + //chose&install language pack & ghost for starter + //install ghost + } + return 0; +} diff --git a/src/my-gists b/src/my-gists index acdacae..5ba1fa2 160000 --- a/src/my-gists +++ b/src/my-gists @@ -1 +1 @@ -Subproject commit acdacaea900ae66301d92823410435a0c1fcfda2 +Subproject commit 5ba1fa2836212f1b6728e432da4bc07fba2bb9db