Skip to content

Commit

Permalink
Added localization support; the strings are declared in English and R…
Browse files Browse the repository at this point in the history
…omanian, for now.
  • Loading branch information
mihaimoga committed Sep 4, 2024
1 parent 72a6b1e commit 645fcca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
28 changes: 25 additions & 3 deletions genUp4win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

#include "pch.h"
#include "resource.h"
#include "genUp4win.h"
#include "AppSettings.h"
#include "VersionInfo.h"
Expand Down Expand Up @@ -70,7 +71,12 @@ bool WriteConfigFile(const std::wstring& strFilePath, const std::wstring& strDow
try {
const HRESULT hr{ CoInitialize(nullptr) };
if (FAILED(hr))
{
_com_error pError(hr);
LPCTSTR lpszErrorMessage = pError.ErrorMessage();
ParentCallback(GENUP4WIN_ERROR, lpszErrorMessage);
return false;
}

CXMLAppSettings pAppSettings(GetAppSettingsFilePath(strFilePath, strProductName), true, true);
pAppSettings.WriteString(strProductName.c_str(), VERSION_ENTRY_ID, pVersionInfo.GetProductVersionAsString().c_str());
Expand All @@ -90,6 +96,7 @@ bool WriteConfigFile(const std::wstring& strFilePath, const std::wstring& strDow

bool ReadConfigFile(const std::wstring& strConfigURL, const std::wstring& strProductName, std::wstring& strLatestVersion, std::wstring& strDownloadURL, fnCallback ParentCallback)
{
CString strStatusMessage;
HRESULT hResult = S_OK;
bool retVal = false;
TCHAR lpszTempPath[_MAX_PATH] = { 0 };
Expand All @@ -102,13 +109,21 @@ bool ReadConfigFile(const std::wstring& strConfigURL, const std::wstring& strPro
{
CString strFileName = lpszFilePath;
strFileName.Replace(_T(".tmp"), _T(".xml"));
ParentCallback(GENUP4WIN_INPROGRESS, _T("Connecting..."));
if (strStatusMessage.LoadString(IDS_CONNECTING))
{
ParentCallback(GENUP4WIN_INPROGRESS, std::wstring(strStatusMessage));
}
if ((hResult = URLDownloadToFile(nullptr, strConfigURL.c_str(), strFileName, 0, nullptr)) == S_OK)
{
try {
const HRESULT hr{ CoInitialize(nullptr) };
if (FAILED(hr))
{
_com_error pError(hr);
LPCTSTR lpszErrorMessage = pError.ErrorMessage();
ParentCallback(GENUP4WIN_ERROR, lpszErrorMessage);
return false;
}

CXMLAppSettings pAppSettings(std::wstring(strFileName), true, true);
strLatestVersion = pAppSettings.GetString(strProductName.c_str(), VERSION_ENTRY_ID);
Expand Down Expand Up @@ -136,6 +151,7 @@ bool ReadConfigFile(const std::wstring& strConfigURL, const std::wstring& strPro

bool CheckForUpdates(const std::wstring& strFilePath, const std::wstring& strConfigURL, fnCallback ParentCallback)
{
CString strStatusMessage;
HRESULT hResult = S_OK;
bool retVal = false;
CVersionInfo pVersionInfo;
Expand All @@ -160,7 +176,10 @@ bool CheckForUpdates(const std::wstring& strFilePath, const std::wstring& strCon
{
CString strFileName = lpszFilePath;
strFileName.Replace(_T(".tmp"), DEFAULT_EXTENSION);
ParentCallback(GENUP4WIN_INPROGRESS, _T("Downloading..."));
if (strStatusMessage.LoadString(IDS_DOWNLOADING))
{
ParentCallback(GENUP4WIN_INPROGRESS, std::wstring(strStatusMessage));
}
if ((hResult = URLDownloadToFile(nullptr, strDownloadURL.c_str(), strFileName, 0, nullptr)) == S_OK)
{
SHELLEXECUTEINFO pShellExecuteInfo;
Expand All @@ -173,7 +192,10 @@ bool CheckForUpdates(const std::wstring& strFilePath, const std::wstring& strCon
pShellExecuteInfo.lpDirectory = nullptr;
pShellExecuteInfo.nShow = SW_SHOWNORMAL;
const bool bLauched = ShellExecuteEx(&pShellExecuteInfo);
ParentCallback(GENUP4WIN_INPROGRESS, bLauched ? _T("The installation started successfully") : _T("Installation failed"));
if (strStatusMessage.LoadString(bLauched ? IDS_SUCCESS : IDS_FAILED))
{
ParentCallback(GENUP4WIN_INPROGRESS, std::wstring(strStatusMessage));
}
retVal = true; // Download was successful
}
else
Expand Down
Binary file modified genUp4win.rc
Binary file not shown.
7 changes: 6 additions & 1 deletion resource.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by genUp4win.rc
//
#define IDS_CONNECTING 101
#define IDS_DOWNLOADING 102
#define IDS_FAILED 103
#define IDS_SUCCESS 104

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
Expand Down
Binary file modified x64/Release/DemoApp.exe
Binary file not shown.
Binary file modified x64/Release/genUp4win.dll
Binary file not shown.

0 comments on commit 645fcca

Please sign in to comment.