From 7729ddb1bc167657c68c7a386574ee21c12c903a Mon Sep 17 00:00:00 2001
From: yumeyao <yumeyao@gmail.com>
Date: Fri, 27 Nov 2020 13:37:15 +0800
Subject: [PATCH] Load distro name and window caption from win32 resource

---
 DistroLauncher/DistributionInfo.cpp | 11 ++++++++
 DistroLauncher/DistributionInfo.h   |  4 +--
 DistroLauncher/DistroLauncher.rc    | 39 ++++++++++++++++++++++++++---
 DistroLauncher/resource.h           |  2 ++
 4 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/DistroLauncher/DistributionInfo.cpp b/DistroLauncher/DistributionInfo.cpp
index 4742f59f..3146cf3c 100644
--- a/DistroLauncher/DistributionInfo.cpp
+++ b/DistroLauncher/DistributionInfo.cpp
@@ -4,6 +4,17 @@
 //
 
 #include "stdafx.h"
+#include "resource.h"
+
+static std::wstring_view LoadStringFromResource(UINT resId, std::wstring_view defaultStr)
+{
+    wchar_t* res;
+    int len = LoadStringW(GetModuleHandle(nullptr), resId, reinterpret_cast<LPWSTR>(&res), 0);
+    return len ? std::wstring_view(res, len) : defaultStr;
+}
+
+const std::wstring DistributionInfo::Name(LoadStringFromResource(IDS_DISTRO_NAME, L"MyDistribution"));
+const std::wstring DistributionInfo::WindowTitle(LoadStringFromResource(IDS_WINDOW_CAPTION, L"My Distribution"));
 
 bool DistributionInfo::CreateUser(std::wstring_view userName)
 {
diff --git a/DistroLauncher/DistributionInfo.h b/DistroLauncher/DistributionInfo.h
index cceb0e24..70e46db4 100644
--- a/DistroLauncher/DistributionInfo.h
+++ b/DistroLauncher/DistributionInfo.h
@@ -13,10 +13,10 @@ namespace DistributionInfo
     //
     // WARNING: This value must not change between versions of your app,
     // otherwise users upgrading from older versions will see launch failures.
-    const std::wstring Name = L"MyDistribution";
+    extern const std::wstring Name;
 
     // The title bar for the console window while the distribution is installing.
-    const std::wstring WindowTitle = L"My Distribution";
+    extern const std::wstring WindowTitle;
 
     // Create and configure a user account.
     bool CreateUser(std::wstring_view userName);
diff --git a/DistroLauncher/DistroLauncher.rc b/DistroLauncher/DistroLauncher.rc
index 80d86b92..a2ead39c 100644
--- a/DistroLauncher/DistroLauncher.rc
+++ b/DistroLauncher/DistroLauncher.rc
@@ -12,6 +12,36 @@
 /////////////////////////////////////////////////////////////////////////////
 #undef APSTUDIO_READONLY_SYMBOLS
 
+/////////////////////////////////////////////////////////////////////////////
+// Neutral resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_ICON1               ICON                    ".\\images\\icon.ico"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE
+BEGIN
+    IDS_DISTRO_NAME         "MyDistribution"
+END
+
+#endif    // Neutral resources
+/////////////////////////////////////////////////////////////////////////////
+
+
 /////////////////////////////////////////////////////////////////////////////
 // English (United States) resources
 
@@ -46,12 +76,13 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
-// Icon
+// String Table
 //
 
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDI_ICON1               ICON                    ".\images\icon.ico"
+STRINGTABLE
+BEGIN
+    IDS_WINDOW_CAPTION      "My Distribution"
+END
 
 #endif    // English (United States) resources
 /////////////////////////////////////////////////////////////////////////////
diff --git a/DistroLauncher/resource.h b/DistroLauncher/resource.h
index e7002b7c..d7b58f38 100644
--- a/DistroLauncher/resource.h
+++ b/DistroLauncher/resource.h
@@ -3,6 +3,8 @@
 // Used by DistroInstaller.rc
 //
 #define IDI_ICON1                       101
+#define IDS_DISTRO_NAME                 150
+#define IDS_WINDOW_CAPTION              1024
 
 // Next default values for new objects
 //