Skip to content

Commit

Permalink
NSIS installer
Browse files Browse the repository at this point in the history
Updated NSIS installer.
Would be ready for release, but: MicrosoftEdge/WebView2Feedback#297
  • Loading branch information
TCNOco committed Jun 15, 2021
1 parent 50cce85 commit 7ce29ac
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 224 deletions.
82 changes: 41 additions & 41 deletions Installer/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
#include <openssl/ssl.h>
using namespace std;

struct software
{
string s_display_name;
string s_version;
};

std::string getOperatingPath() {
const HMODULE h_module = GetModuleHandleW(nullptr);
WCHAR pth[MAX_PATH];
Expand Down Expand Up @@ -140,7 +134,7 @@ inline bool file_exists(const std::string& name) {



vector<software> v_webview, v_aspcore, v_desktop_runtime;
int webview_count, aspcore_count, desktop_runtime_count = 0;
void find_installed_runtimes(bool x32);
wstring s2_ws(const string& s)
{
Expand Down Expand Up @@ -172,17 +166,17 @@ void wait_for_input()
_getch();
}

const bool test_mode = true;
const bool test_downloads = true;
const bool test_mode = false;
const bool test_downloads = false;
const bool test_installs = false;
int main()
{
// Goal of this application:
// - Check for the existence of required runtimes, and install them if missing. [First run ever on a computer]
// --- [Unlikely] Maybe in the future: Verify application folders, and handle zipping and sending error logs? Possibly just the first or none of these.
const string operating_path = getOperatingPath();
cout << "Welcome to the TcNo Account Switcher installer - Runtime installer" << endl <<
SetConsoleTitle(_T("TcNo Account Switcher - Runtime installer"));
cout << "Welcome to the TcNo Account Switcher - Runtime installer" << endl <<
"------------------------------------------------------------------------" << endl << endl <<
"Currently installed runtimes:" << endl;

Expand All @@ -192,24 +186,24 @@ int main()
cout << "------------------------------------------------------------------------" << endl << endl;

/* Warn about runtime downloads */
if (v_webview.empty() || v_aspcore.empty() || v_desktop_runtime.empty() || test_mode)
if (webview_count == 0 || aspcore_count == 0 || desktop_runtime_count == 0 || test_mode)
{
cout << "One or more runtimes are not installed:" << endl;
int total = 0;
if (v_webview.empty()) {
cout << " + Microsoft WebView2 Runtime [1,70 MB + ~120 MB while installing]" << endl;
if (webview_count == 0) {
cout << " + Microsoft WebView2 Runtime [~1,70 MB + ~120 MB while installing]" << endl;
total += 122;
}
if (v_desktop_runtime.empty()){
cout << " + Microsoft .NET 5 Desktop Runtime [52,3 MB]" << endl;
if (aspcore_count == 0){
cout << " + Microsoft .NET 5 Desktop Runtime [~52,3 MB]" << endl;
total += 52;
}
if (v_aspcore.empty()){
cout << " + Microsoft Microsoft ASP.NET Core 5.0 Runtime [7,90 MB]" << endl;
if (desktop_runtime_count == 0){
cout << " + Microsoft Microsoft ASP.NET Core 5.0 Runtime [~7,90 MB]" << endl;
total += 8;
}

cout << " = Total download size : " << total << " MB" << endl << endl <<
cout << " = Total download size: ~" << total << " MB" << endl << endl <<
"Press any key to start download..." << endl;

wait_for_input();
Expand All @@ -236,7 +230,7 @@ int main()
return 1;
}

if (v_webview.empty() || test_downloads)
if (webview_count == 0 || test_downloads)
{
current_download = w_runtime_name;
if (!download_file(w_runtime.c_str(), w_runtime_local.c_str()))
Expand All @@ -248,7 +242,7 @@ int main()
else w_runtime_install = true;
}

if (v_desktop_runtime.empty() || test_downloads)
if (desktop_runtime_count == 0 || test_downloads)
{
current_download = d_runtime_name;
if (!download_file(d_runtime.c_str(), d_runtime_local.c_str()))
Expand All @@ -259,7 +253,7 @@ int main()
else d_runtime_install = true;
}

if (v_aspcore.empty() || test_downloads)
if (aspcore_count == 0 || test_downloads)
{
current_download = a_runtime_name;
if (!download_file(a_runtime.c_str(), a_runtime_local.c_str()))
Expand All @@ -277,7 +271,7 @@ int main()
{
cout << "------------------------------------------------------------------------" << endl << endl <<
"One or more are ready for install. If and when prompted if you would like to install, click 'Yes'." << endl << endl <<
"Press any key to start download..." << endl;
"Press any key to start install..." << endl;
wait_for_input();

if (w_runtime_install || test_installs)
Expand All @@ -289,10 +283,23 @@ int main()
if (a_runtime_install || test_installs)
install_runtime(a_runtime_local, a_runtime_name, true);
}
cout << "------------------------------------------------------------------------" << endl << endl;

system("cls");
cout << "Currently installed runtimes:" << endl;
find_installed_runtimes(false);
cout << "------------------------------------------------------------------------" << endl << endl <<
"Verify you meet the minimum recommended requirements:" << endl;
}
else
{
cout << "It looks like everything is installed. Verify you meet the minimum recommended requirements:" << endl;
}

cout << "That should be everything. You can use TcNo-Acc-Switcher.exe to run the program." << endl << endl <<
cout << " - Windows Desktop Runtime 5.0.7+" << endl <<
" - ASP.NET Core 5.0.7+." << endl <<
" - Edge WebView2 Runtime 91.0+" << endl <<
"------------------------------------------------------------------------" << endl << endl <<
"That should be everything. The main program, TcNo-Acc-Switcher.exe, will auto-run when you press a key to continue." << endl << endl <<
"If it doesn't work, please refer to install instructions, here:" << endl <<
"https://github.com/TcNobo/TcNo-Acc-Switcher#required-runtimes-download-and-install" << endl << endl;

Expand Down Expand Up @@ -352,35 +359,28 @@ void find_installed_runtimes(const bool x32)
dw_v_buffer_size = sizeof(s_version);
if (RegQueryValueEx(h_app_key, L"DisplayName", nullptr, &dw_type, reinterpret_cast<unsigned char*>(s_display_name), &dw_buffer_size) == ERROR_SUCCESS &&
RegQueryValueEx(h_app_key, L"DisplayVersion", nullptr, &dw_type, reinterpret_cast<unsigned char*>(s_version), &dw_v_buffer_size) == ERROR_SUCCESS)
{
string name(s_display_name, s_display_name + dw_buffer_size);
string version(s_version, s_version + dw_v_buffer_size);

if (name.find("WebView2") != std::string::npos)
{
if (wcsstr(s_display_name, L"WebView2") != nullptr)
{
v_webview.emplace_back(software { name, version });
wprintf(L" - %s\n", s_display_name);
webview_count += 1;
wprintf(L" - %s ", s_display_name);
wprintf(L"[%s]\n", s_version);
}

if (name.find("Desktop Runtime") != std::string::npos && name.find("x64") != std::string::npos)
if (wcsstr(s_display_name, L"Desktop Runtime") != nullptr && wcsstr(s_display_name, L"x64") != nullptr)
{
v_desktop_runtime.emplace_back(software{ name, version });
desktop_runtime_count += 1;
wprintf(L" - %s\n", s_display_name);
}

if (name.find("ASP.NET Core 5") != std::string::npos)
if (wcsstr(s_display_name, L"ASP.NET Core 5") != nullptr)
{
v_aspcore.emplace_back(software{ name, version });
aspcore_count += 1;
wprintf(L" - %s\n", s_display_name);
}
}
else {
//Display name value doe not exist, this application was probably uninstalled.
}

RegCloseKey(h_app_key);
}
}

RegCloseKey(h_uninst_key);
}
110 changes: 110 additions & 0 deletions Installer/Installer.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "C:\\Users\\TCNO\\source\\repos\\TcNo-Acc-Switcher\\TcNo-Acc-Switcher-Tray\\favicon.ico"


/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040004b0"
BEGIN
VALUE "CompanyName", "TechNobo (Wesley Pyburn)"
VALUE "FileDescription", "Easy redistributable installer for the TcNo Account Switcher"
VALUE "FileVersion", "1.0.0.1"
VALUE "InternalName", "_First_R.exe"
VALUE "LegalCopyright", "Copyright � TechNobo (Wesley Pyburn) 2019-2021"
VALUE "OriginalFilename", "_First_Run_Installer.exe"
VALUE "ProductName", "TcNo Account Switcher - Redistributable Installer"
VALUE "ProductVersion", "1.0.0.1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x400, 1200
END
END

#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

11 changes: 11 additions & 0 deletions Installer/Installer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ProjectGuid>{3e53d5b9-c3bd-4d56-b228-1605664b35a4}</ProjectGuid>
<RootNamespace>Installer</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>_First_Run_Installer</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -82,9 +83,11 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\TcNo-Acc-Switcher-Client\bin\Installer\</OutDir>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<VcpkgUseStatic>true</VcpkgUseStatic>
Expand Down Expand Up @@ -152,6 +155,7 @@
<AdditionalIncludeDirectories>E:\code\vcpkg\installed\x64-windows-static\include</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -168,6 +172,13 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="progress_bar.hpp" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Installer.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="..\TcNo-Acc-Switcher-Tray\favicon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
13 changes: 13 additions & 0 deletions Installer/Installer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,18 @@
<ClInclude Include="progress_bar.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Installer.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="..\TcNo-Acc-Switcher-Tray\favicon.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions Installer/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Installer.rc
//
#define IDI_ICON1 101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Loading

0 comments on commit 7ce29ac

Please sign in to comment.