Skip to content

Commit

Permalink
Mwasplund/windows app (#113)
Browse files Browse the repository at this point in the history
* Add windows app build target
* Create sample app
* Cleanup package lock relative paths

Co-authored-by: Matthew Asplund <[email protected]>
  • Loading branch information
mwasplund and Matthew Asplund authored Jan 20, 2022
1 parent 0fc26d5 commit 43cd272
Show file tree
Hide file tree
Showing 37 changed files with 1,826 additions and 609 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
run: soup build ./Soup/Samples/Cpp/ParseJsonFile/ -flavor ${{matrix.config}} -v:d
- name: Soup Build Cpp StaticLibrary
run: soup build ./Soup/Samples/Cpp/StaticLibrary/Application/ -flavor ${{matrix.config}} -v:d
- name: Soup Build Cpp WindowsProject
run: soup build ./Soup/Samples/Cpp/WindowsProject/ -flavor ${{matrix.config}} -v:d

- name: Soup Install CSharp BuildExtension
run: soup install ./Soup/Samples/CSharp/BuildExtension/Executable/
Expand Down
8 changes: 8 additions & 0 deletions Samples/Cpp/WindowsProject/Recipe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Name = "Samples.Cpp.WindowsApplication"
Language = "C++"
Type = "Windows"
Version = "1.1.3"
Resources = "WindowsProject.rc"
Source = [
"WindowsProject.cpp"
]
30 changes: 30 additions & 0 deletions Samples/Cpp/WindowsProject/Resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by WindowsProject.rc

#define IDS_APP_TITLE 103

#define IDR_MAINFRAME 128
#define IDD_WINDOWSPROJECT_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_WINDOWSPROJECT 107
#define IDI_SMALL 108
#define IDC_WINDOWSPROJECT 109
#define IDC_MYICON 2
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NO_MFC 130
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif
186 changes: 186 additions & 0 deletions Samples/Cpp/WindowsProject/WindowsProject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// WindowsProject.cpp : Defines the entry point for the application.
//

#include "framework.h"
#include "WindowsProject.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_WINDOWSPROJECT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOWSPROJECT));

MSG msg;

// Main message loop:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINDOWSPROJECT);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassExW(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable

HWND hWnd = CreateWindowW(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
nullptr,
nullptr,
hInstance,
nullptr);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
UNREFERENCED_PARAMETER(hdc);
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}

return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}

return (INT_PTR)FALSE;
}
3 changes: 3 additions & 0 deletions Samples/Cpp/WindowsProject/WindowsProject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "resource.h"
Binary file added Samples/Cpp/WindowsProject/WindowsProject.ico
Binary file not shown.
Binary file added Samples/Cpp/WindowsProject/WindowsProject.rc
Binary file not shown.
15 changes: 15 additions & 0 deletions Samples/Cpp/WindowsProject/framework.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// framework.h : include file for standard system include files,
// or project specific include files
//

#pragma once

#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
Binary file added Samples/Cpp/WindowsProject/small.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions Samples/Cpp/WindowsProject/targetver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

// // Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
14 changes: 7 additions & 7 deletions Source/Client/CLI/PackageLock.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[Projects]
"C++" = [
{ Name = "Soup", Version = "C:/Users/mwasp/source/repos/Soup/Source/Client/CLI" },
{ Name = "Soup.Core", Version = "C:/Users/mwasp/source/repos/Soup/Source/Client/Core/" },
{ Name = "Soup", Version = "./" },
{ Name = "Soup.Core", Version = "../Core/" },
{ Name = "json11", Version = "[email protected]" },
{ Name = "Opal", Version = "[email protected]" },
{ Name = "toml11", Version = "[email protected]" },
{ Name = "Monitor.Host", Version = "C:/Users/mwasp/source/repos/Soup/Source/Monitor/Host/" },
{ Name = "Detours", Version = "C:/Users/mwasp/source/repos/Soup/Dependencies/Detours/src/" },
{ Name = "Monitor.Shared", Version = "C:/Users/mwasp/source/repos/Soup/Source/Monitor/Shared/" },
{ Name = "Monitor.Host", Version = "../../Monitor/Host/" },
{ Name = "Detours", Version = "../../../Dependencies/Detours/src/" },
{ Name = "Monitor.Shared", Version = "../../../Monitor/Shared/" },
{ Name = "Soup.Test.Assert", Version = "[email protected]" },
{ Name = "copy", Version = "C:/Users/mwasp/source/repos/Soup/Source/Tools/Copy/" },
{ Name = "mkdir", Version = "C:/Users/mwasp/source/repos/Soup/Source/Tools/Mkdir/" },
{ Name = "copy", Version = "../../Tools/Copy/" },
{ Name = "mkdir", Version = "../../Tools/Mkdir/" },
]
"C#" = [
{ Name = "Soup.Test.Cpp", Version = "[email protected]" },
Expand Down
12 changes: 9 additions & 3 deletions Source/Client/Core/Source/Build/ProjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Soup::Core
{
private:
bool _hasPackageLock;
Path _packageLockRoot;
std::map<std::string, std::map<std::string, PackageReference>> _packageLanguageLock;
std::map<std::string, Recipe> _knownRecipes;
std::map<std::string, RootRecipe> _knownRootRecipes;
Expand All @@ -44,6 +45,7 @@ namespace Soup::Core
{
Log::Info("Package lock loaded");

_packageLockRoot = projectRoot;
_packageLanguageLock = packageLock.GetProjects();
_hasPackageLock = true;
}
Expand Down Expand Up @@ -101,8 +103,8 @@ namespace Soup::Core
}
else
{
Log::Error("The dependency Recipe version has not been installed: " + dependency.ToString() + " [" + projectRoot.ToString() + "]");
Log::HighPriority("Run `install` and try again");
Log::Error("The dependency Recipe version has not been installed: " + dependency.ToString() + " -> " + dependencyProjectRoot.ToString() + " [" + projectRoot.ToString() + "]");
Log::HighPriority("Run `restore` and try again");
}

// Nothing we can do, exit
Expand Down Expand Up @@ -192,7 +194,6 @@ namespace Soup::Core
}
}

private:
Path GetPackageReferencePath(
const Path& workingDirectory,
const PackageReference& reference,
Expand Down Expand Up @@ -225,6 +226,10 @@ namespace Soup::Core
{
// Allow overload to local version
packagePath = packageVersion->second.GetPath();
if (!packagePath.HasRoot())
{
packagePath = _packageLockRoot + packagePath;
}
}
else
{
Expand All @@ -248,6 +253,7 @@ namespace Soup::Core
return packagePath;
}

private:
Path GetSoupUserDataPath() const
{
auto result = System::IFileSystem::Current().GetUserProfileDirectory() +
Expand Down
Loading

0 comments on commit 43cd272

Please sign in to comment.