Skip to content

Commit

Permalink
Update 0.6b
Browse files Browse the repository at this point in the history
  • Loading branch information
XyLe-GBP committed Sep 30, 2023
1 parent 70a12f7 commit 96ebbeb
Show file tree
Hide file tree
Showing 25 changed files with 2,171 additions and 82 deletions.
172 changes: 172 additions & 0 deletions ApplicationUpdater/ApplicationUpdater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// ApplicationUpdater.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "Common.h"

int main()
{
Common* common = new Common;
TCHAR Path[MAX_PATH + 1];
string AppPath, AppType;

if (0 != GetModuleFileName(NULL, Path, MAX_PATH)) {

TCHAR drive[MAX_PATH + 1]
, dir[MAX_PATH + 1]
, fname[MAX_PATH + 1]
, ext[MAX_PATH + 1];

_tsplitpath_s(Path, drive, dir, fname, ext);

string sdrive = common->TWStringToString(drive)
, sdir = common->TWStringToString(dir)
, sfname = common->TWStringToString(fname)
, sext = common->TWStringToString(ext);

if (PathFileExists(common->StringToWString(sdrive + sdir + "updater.dat").c_str())) {
cout << "Updater - Application Update Utility v1.2" << endl;
cout << "Copyright (C) 2022 XyLe. All Rights Reserved.\n" << endl;

ifstream ifs(common->StringToWString(sdrive + sdir + "updater.dat").c_str());
if (!ifs) {
MessageBox(NULL, TEXT("Could not open file."), TEXT("Error"), MB_ICONWARNING);
SAFE_DELETE(common);
return -1;
}
else {
string buf;
int count = 0;
while (getline(ifs, buf))
{
if (count == 0) {
AppPath = buf;
}
else {
AppType = buf;
}
count++;
}
}
ifs.close();
DeleteFile(common->StringToWString(sdrive + sdir + "updater.dat").c_str());

string destmca = sdrive + "\\mca-coh.exe";
MoveFile(common->StringToWString(AppPath + "\\res\\mca-coh.exe").c_str(), common->StringToWString(destmca).c_str());
common->DeleteDirectory(common->StringToWString(AppPath).c_str());
if (PathFileExists(common->StringToWString(sdrive + sdir + "mca-coh-gui.zip").c_str())) {
HRESULT hr;
IShellDispatch* pShellDisp{};
if (CoInitializeEx(0, COINIT_MULTITHREADED) == 0) {
cout << "CoInitializeEx: S_OK" << endl;
OutputDebugString(_T("CoInitializeEx: S_OK\n"));
}
else {
cout << "WARNING: CoInitializeEx: S_FALSE" << endl;
OutputDebugString(_T("CoInitializeEx: S_FALSE\n"));
}
hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShellDisp));
if (FAILED(hr)) {
CoUninitialize();
SAFE_DELETE(common);
return -1;
}

string tmpd = sdrive + sdir + "updater-temp";
if (_mkdir(tmpd.c_str()) == 0) {
cout << "_mkdir(" + tmpd + ") completed." << endl;
}
else {
cout << "ERROR: _mkdir(" + tmpd + ") failed." << endl;
MessageBox(NULL, TEXT("failed create directory."), TEXT("Error"), MB_ICONWARNING);
SAFE_DELETE(common);
return -1;
}

TCHAR* SourcePath = common->ConvertTCHAR(common->StringToWString(sdrive + sdir + "mca-coh-gui.zip").c_str());
TCHAR* ExtPath = common->ConvertTCHAR(common->StringToWString(sdrive + sdir + "updater-temp").c_str());

if (common->ExtractZip(pShellDisp, SourcePath, ExtPath) == TRUE) {
cout << "'" + sdrive + sdir + "mca-coh-gui.zip' to '" + sdrive + sdir + "updater-temp' extracted." << endl;
CoUninitialize();
SAFE_FREE(SourcePath);
SAFE_FREE(ExtPath);
SAFE_DELETE(common);
}
else {
cout << "ERROR: '" + sdrive + sdir + "mca-coh-gui.zip' to '" + sdrive + sdir + "updater-temp' extract failed." << endl;
CoUninitialize();
SAFE_FREE(SourcePath);
SAFE_FREE(ExtPath);
SAFE_DELETE(common);
return -1;
}

if (AppType == "release") {
cout << "Type: release" << endl;
vector<tstring> tvector;
common->CopyDirectory(common->StringToWString(sdrive + sdir + "updater-temp\\release\\res").c_str(), common->StringToWString(AppPath + "\\res").c_str());
common->CopyDirectoryFiles(common->StringToWString(sdrive + sdir + "updater-temp\\release").c_str(), common->StringToWString(AppPath + "\\").c_str(), tvector);
}
else if (AppType == "portable") {
cout << "Type: portable" << endl;
vector<tstring> tvector;
common->CopyDirectory(common->StringToWString(sdrive + sdir + "updater-temp\\release-portable\\res").c_str(), common->StringToWString(AppPath + "\\res").c_str());
common->CopyDirectoryFiles(common->StringToWString(sdrive + sdir + "updater-temp\\release-portable").c_str(), common->StringToWString(AppPath + "\\").c_str(), tvector);
}
else {
cout << "ERROR: Unknown type." << endl;
MessageBox(NULL, TEXT("unknown release type."), TEXT("Error"), MB_ICONWARNING);
SAFE_DELETE(common);
return -1;
}

MoveFile(common->StringToWString(destmca).c_str(), common->StringToWString(AppPath + "\\res\\mca-coh.exe").c_str());
ofstream ofs;
string fn = AppPath + "\\updated.dat";
ofs.open(fn, ios::out);
ofs << "updated." << endl;
ofs.close();

wstring ExectablePath = common->StringToWString(AppPath) + L"\\mca-coh-gui.exe";
wstring Current = common->StringToWString(AppPath);
TCHAR* TExectablePath = common->ConvertTCHAR(ExectablePath.c_str());
TCHAR* TCurrent = common->ConvertTCHAR(Current.c_str());

ShellExecute(NULL, _T("open"), TExectablePath, NULL, TCurrent, SW_SHOWNORMAL);

SAFE_FREE(TExectablePath);
SAFE_FREE(TCurrent);
SAFE_DELETE(common);

return 0;
}
else {
MessageBox(NULL, TEXT("Target file not found."), TEXT("Error"), MB_ICONWARNING);
SAFE_DELETE(common);
return -1;
}
}
else {
SAFE_DELETE(common);
cout << "Updater - Application Auto Update Utility v1.2" << endl;
cout << "Copyright (C) 2022 XyLe. All Rights Reserved." << endl;
MessageBox(NULL, TEXT("Update information file not found."), TEXT("Warning"), MB_ICONWARNING);
return -1;
}
}
else {
SAFE_DELETE(common);
return -1;
}
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント:
// 1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
// 2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
// 3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
// 4. エラー一覧ウィンドウを使用してエラーを表示します
// 5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
// 6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します
Binary file added ApplicationUpdater/ApplicationUpdater.rc
Binary file not shown.
31 changes: 31 additions & 0 deletions ApplicationUpdater/ApplicationUpdater.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ApplicationUpdater", "ApplicationUpdater.vcxproj", "{DF78F33D-58BA-4FE1-82F3-66209CC0223E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Debug|x64.ActiveCfg = Debug|x64
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Debug|x64.Build.0 = Debug|x64
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Debug|x86.ActiveCfg = Debug|Win32
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Debug|x86.Build.0 = Debug|Win32
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Release|x64.ActiveCfg = Release|x64
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Release|x64.Build.0 = Release|x64
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Release|x86.ActiveCfg = Release|Win32
{DF78F33D-58BA-4FE1-82F3-66209CC0223E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F19B695F-566E-4C38-8D86-B240E5AEF6C6}
EndGlobalSection
EndGlobal
166 changes: 166 additions & 0 deletions ApplicationUpdater/ApplicationUpdater.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{df78f33d-58ba-4fe1-82f3-66209cc0223e}</ProjectGuid>
<RootNamespace>ApplicationUpdater</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
<TargetName>updater</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
<TargetName>updater</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)updater$(TargetExt)</OutputFile>
<AdditionalDependencies>Shlwapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ApplicationUpdater.cpp" />
<ClCompile Include="Common.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Common.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ApplicationUpdater.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="Icon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit 96ebbeb

Please sign in to comment.