Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki-Codes committed Jun 6, 2021
1 parent 4a40eb9 commit c102d62
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 47 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ bin/
obj/
deploy/
Setup/Release/
Setup/Debug/
Setup/Debug/
*.tlog
*.iobj
*.ipdb
*.filters
*.pdb
*.log
*.obj
*.idb
*.recipe
*.ilk
12 changes: 12 additions & 0 deletions Anamnesis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Anamnesis", "Anamnesis\Anam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UpdateExtractor", "UpdateExtractor\UpdateExtractor.csproj", "{28786A77-C234-43B9-8365-33A70C4A216A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Launcher", "Launcher\Launcher.vcxproj", "{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,6 +43,16 @@ Global
{28786A77-C234-43B9-8365-33A70C4A216A}.Release|x64.Build.0 = Release|Any CPU
{28786A77-C234-43B9-8365-33A70C4A216A}.Release|x86.ActiveCfg = Release|Any CPU
{28786A77-C234-43B9-8365-33A70C4A216A}.Release|x86.Build.0 = Release|Any CPU
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Debug|Any CPU.ActiveCfg = Debug|Win32
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Debug|x64.ActiveCfg = Debug|x64
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Debug|x64.Build.0 = Debug|x64
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Debug|x86.ActiveCfg = Debug|Win32
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Debug|x86.Build.0 = Debug|Win32
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Release|Any CPU.ActiveCfg = Release|Win32
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Release|x64.ActiveCfg = Release|x64
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Release|x64.Build.0 = Release|x64
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Release|x86.ActiveCfg = Release|Win32
{787A5F21-3FA7-4C3C-8952-EE2A473CD12B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 6 additions & 1 deletion Anamnesis/Anamnesis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>Anamnesis</RootNamespace>
<ApplicationIcon>Assets\Concept Matrix.ico</ApplicationIcon>
<OutputPath>.\bin\</OutputPath>
<OutputPath>..\deploy\bin\</OutputPath>
<DocumentationFile>.\obj\Anamnesis.xml</DocumentationFile>
<NoWarn>1701;1702;SA1503;CS1591;SA1401;SA1516;CS0067;IDE0027;IDE0025;SA1011;SA1134;</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down Expand Up @@ -351,6 +351,7 @@

<ItemGroup>
<Folder Include="Core\Localization\" />
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
Expand All @@ -366,6 +367,10 @@
</None>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="move $(OutDir)\Data $(OutDir)..\Data&#xD;&#xA;move $(OutDir)\Languages $(OutDir)..\Languages" />
</Target>

</Project>


Expand Down
6 changes: 3 additions & 3 deletions Anamnesis/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void CheckWorkingDirectory()
string currentDir = Directory.GetCurrentDirectory();
Log.Information($"Check Working Directory: \"{currentDir}\"");

if (!File.Exists(currentDir + "/Anamnesis.exe"))
if (!File.Exists(currentDir + "/bin/Anamnesis.exe"))
{
string? currentPath = AppContext.BaseDirectory;

Expand All @@ -132,9 +132,9 @@ private void CheckWorkingDirectory()
if (string.IsNullOrEmpty(newDir))
throw new Exception($"Failed to get current directory");

currentDir = Path.GetFullPath(newDir);
currentDir = Path.GetFullPath(newDir + "/../");

if (!File.Exists(currentDir + "/Anamnesis.exe"))
if (!File.Exists(currentDir + "/bin/Anamnesis.exe"))
throw new Exception($"Incorrect new working directory: {currentDir}");

Directory.SetCurrentDirectory(currentDir);
Expand Down
Binary file modified Anamnesis/Assets/Concept Matrix.ico
Binary file not shown.
17 changes: 0 additions & 17 deletions Anamnesis/Properties/PublishProfiles/PublishProfile.pubxml

This file was deleted.

9 changes: 3 additions & 6 deletions Anamnesis/Updater/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Anamnesis.Updater

public class UpdateService : ServiceBase<UpdateService>
{
public const string VersionFile = "Version.txt";
public const string VersionFile = "bin/Version.txt";

private const string Repository = "imchillin/Anamnesis";

Expand Down Expand Up @@ -172,10 +172,6 @@ public async Task DoUpdate(Action<double>? updateProgress = null)
// While testing, do not copy the update files over our working files.
if (Debugger.IsAttached)
{
string? sourceDir = Path.GetDirectoryName(currentExePath);
if (string.IsNullOrEmpty(sourceDir))
throw new Exception("Unable to determine source directory");

Directory.Delete(UpdateTempDir, true);
string[] paths = Directory.GetFiles(".", "*.*", SearchOption.AllDirectories);
foreach (string path in paths)
Expand All @@ -191,8 +187,9 @@ public async Task DoUpdate(Action<double>? updateProgress = null)
}

// Start the update extractor
string currentDir = Directory.GetCurrentDirectory();
string procName = Process.GetCurrentProcess().ProcessName;
ProcessStartInfo start = new ProcessStartInfo(UpdateTempDir + "/Updater/UpdateExtractor.exe", $"\"{currentExePath}\" {procName}");
ProcessStartInfo start = new ProcessStartInfo(UpdateTempDir + "/Updater/UpdateExtractor.exe", $"\"{currentDir}\" {procName}");
Process.Start(start);

// Shutdown anamnesis
Expand Down
86 changes: 86 additions & 0 deletions Launcher/Launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Launcher.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
#include <windows.h>

#include "resource.h"

#pragma comment(lib, "urlmon.lib")

using namespace std;

string exec(const char* cmd)
{
array<char, 128> buffer;
string result;
unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);

if (!pipe)
{
throw runtime_error("popen() failed!");
}

while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
{
result += buffer.data();
}

return result;
}

std::string GetCurrentDirectory()
{
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::string::size_type pos = std::string(buffer).find_last_of("\\/");

return std::string(buffer).substr(0, pos);
}

int main()
{
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));


cout << "Check .Net desktop runtime\n";
string result = exec("dotnet --info");

if (result.find("Microsoft.WindowsDesktop.App 5.0.6") == std::string::npos)
{
cout << "Desktop runtime not found\n";

string setupFile = GetCurrentDirectory().append("\\setupdotnet5.exe");

wstring dwnld_URL = L"https://download.visualstudio.microsoft.com/download/pr/6279dc90-f437-4481-82a5-73dd9f97da06/6519ef44735fd31115b9b1a81d6ff1e8/windowsdesktop-runtime-5.0.6-win-x64.exe";
wstring stemp = wstring(setupFile.begin(), setupFile.end());
if (S_OK == URLDownloadToFile(NULL, dwnld_URL.c_str(), stemp.c_str(), 0, NULL))
{
cout << "Downloaded setup\n";
system(setupFile.c_str());
remove(setupFile.c_str());
}
else
{
cout << "Setup download failed\n";
system("pause");
return 2;
}
}
else
{
cout << "Desktop runtime found\n";
}

string anaFile = "start ";
anaFile.append(GetCurrentDirectory().append("\\bin\\Anamnesis.exe"));
system(anaFile.c_str());
}
Loading

0 comments on commit c102d62

Please sign in to comment.