Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Aug 9, 2022
1 parent ecee3a4 commit 23aad83
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 64 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"xstring": "cpp"
}
}
40 changes: 40 additions & 0 deletions src/download_temp_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <string>
#include <windows.h>
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;
}
63 changes: 0 additions & 63 deletions src/draft.cpp

This file was deleted.

43 changes: 43 additions & 0 deletions src/ghost_installer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <windows.h>
#include <shlobj_core.h>
#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;
}

0 comments on commit 23aad83

Please sign in to comment.