]> repos.lx-s.de Git - winmute.git/commitdiff
Prepare for new log facilities
authorlx-s <lx-s@users.noreply.github.com>
Tue, 28 Jan 2025 07:54:28 +0000 (08:54 +0100)
committerlx-s <lx-s@users.noreply.github.com>
Tue, 28 Jan 2025 07:54:28 +0000 (08:54 +0100)
Dist/bin/changelog.txt
WinMute/LogDialog.cpp [new file with mode: 0644]
WinMute/Settings_GeneralDlg.cpp
WinMute/WMLog.cpp
WinMute/WMLog.h
WinMute/WinMute.cpp
WinMute/WinMute.rc
WinMute/WinMute.vcxproj
WinMute/WinMute.vcxproj.filters
WinMute/resource.h

index eda95ddcabeca8eb68a22e656c353d336f73529b..bdc7b1e516275b4743e76c4559c981d45f1fc2a8 100644 (file)
@@ -1,5 +1,6 @@
 Version 2.5.1 (2024-05-03)
  * Added new language: Simplified Chinese (thanks to https://translate.codeberg.org/user/richzhl/)
+ * Updated translations (thanks to all contributors!)
 
 Version 2.5.0.1 (2024-02-26)
  * Fixed update-check file for chocolatey package manager
diff --git a/WinMute/LogDialog.cpp b/WinMute/LogDialog.cpp
new file mode 100644 (file)
index 0000000..3a77cbf
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ WinMute
+           Copyright (c) 2024, Alexander Steinhoefer
+
+-----------------------------------------------------------------------------
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+    * Neither the name of the author nor the names of its contributors may
+      be used to endorse or promote products derived from this software
+      without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-----------------------------------------------------------------------------
+*/
+
+#include "common.h"
+
+static void TranslateLogDlgProc(HWND hDlg)
+{
+   WMi18n &i18n = WMi18n::GetInstance();
+   SetWindowText(hDlg, i18n.GetTranslationW("log.title").c_str());
+}
+
+INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+   AboutDlgData *dlgData =
+      reinterpret_cast<AboutDlgData *>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
+   switch (msg) {
+   case WM_INITDIALOG:
+   {
+      dlgData = new AboutDlgData();
+      SetWindowLongPtr(hDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(dlgData));
+
+      dlgData->hTabCtrl = GetDlgItem(hDlg, IDC_ABOUT_TAB);
+
+      WMi18n &i18n = WMi18n::GetInstance();
+      InsertTabItem(dlgData->hTabCtrl, ABOUT_TAB_GENERAL, i18n.GetTranslationW("about.tab.winmute"));
+      InsertTabItem(dlgData->hTabCtrl, ABOUT_TAB_LICENSE, i18n.GetTranslationW("about.tab.license"));
+
+      TranslateAboutDlgProc(hDlg);
+
+      dlgData->hTabs[ABOUT_TAB_GENERAL] = CreateDialog(
+         nullptr,
+         MAKEINTRESOURCE(IDD_ABOUT_WINMUTE),
+         hDlg,
+         About_GeneralDlgProc);
+      dlgData->hTabs[ABOUT_TAB_LICENSE] = CreateDialog(
+         nullptr,
+         MAKEINTRESOURCE(IDD_ABOUT_LICENSE),
+         hDlg,
+         About_LicenseDlgProc);
+
+
+      // Set title font
+      LOGFONT font;
+      font.lfHeight = 32;
+      font.lfWidth = 0;
+      font.lfEscapement = 0;
+      font.lfOrientation = 0;
+      font.lfWeight = FW_BOLD;
+      font.lfItalic = false;
+      font.lfUnderline = false;
+      font.lfStrikeOut = false;
+      font.lfEscapement = 0;
+      font.lfOrientation = 0;
+      font.lfOutPrecision = OUT_DEFAULT_PRECIS;
+      font.lfClipPrecision = CLIP_STROKE_PRECIS | CLIP_MASK | CLIP_TT_ALWAYS | CLIP_LH_ANGLES;
+      font.lfQuality = CLEARTYPE_QUALITY;
+      font.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
+      wcscpy_s(font.lfFaceName, L"Segoe UI");
+
+      dlgData->hTitleFont = CreateFontIndirect(&font);
+      SendMessage(
+         hTitle,
+         WM_SETFONT,
+         reinterpret_cast<WPARAM>(dlgData->hTitleFont),
+         TRUE);
+
+      HICON hIcon = LoadIcon(
+         GetModuleHandle(nullptr),
+         MAKEINTRESOURCE(IDI_TRAY_DARK));
+      SendMessageW(hDlg, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hIcon));
+
+      return TRUE;
+   }
+   case WM_COMMAND:
+      return 0;
+   case WM_DESTROY:
+      DeleteObject(dlgData->hTitleFont);
+      delete dlgData;
+      SetWindowLongPtrW(hDlg, GWLP_USERDATA, 0);
+      return 0;
+   case WM_CLOSE:
+      EndDialog(hDlg, 0);
+      return TRUE;
+   default:
+      break;
+   }
+   return FALSE;
+}
index 0957f599fc76e1ba7e11805710ea57f96a0ba1d3..bceb468693fed70f5bc8554dabf2fbf9b3ad835f 100644 (file)
@@ -199,7 +199,7 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA
 
       const int enableLog = Button_GetCheck(hLogging) == BST_CHECKED;
       dlgData->settings->SetValue(SettingsKey::LOGGING_ENABLED, enableLog);
-      WMLog::GetInstance().SetEnabled(enableLog);
+      WMLog::GetInstance().EnableLogFile(enableLog);
 
       HWND hLanguageSelector = GetDlgItem(hDlg, IDC_LANGUAGE);
       const auto curLangSel = ComboBox_GetCurSel(hLanguageSelector);
index da2138005fda3cf05f68e8a299e0e6756df79f19..418456772f3321101a423746c36492214b8d65bd 100644 (file)
@@ -77,7 +77,7 @@ void WMLog::DeleteLogFile()
    DeleteFileW(logFilePath.c_str());
 }
 
-void WMLog::SetEnabled(bool enable)
+void WMLog::EnableLogFile(bool enable)
 {
    const std::lock_guard lock(logMutex_);
    if (enable == enabled_) {
@@ -127,6 +127,12 @@ void WMLog::WriteMessage(const wchar_t* level, const wchar_t* msg)
    logFile_.flush();
 }
 
+std::vector<LogMessage> WMLog::GetLogMessages() const
+{
+   const std::scoped_lock<std::mutex> lock(logMutex_);
+   return logMessages_;
+}
+
 void WMLog::LogDebug(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...)
 {
    if (!enabled_) {
index 13c4d22c032658f6d57b45206cffd76c7f511e83..c59b79c43b3e0d64a46657e6c2b7dba1d9c1c168 100644 (file)
@@ -35,6 +35,18 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "common.h"
 
+enum class LogLevel {
+   Debug,
+   Info,
+   Error,
+};
+
+struct LogMessage {
+   LogLevel level;
+   std::string time;
+   std::string message;
+};
+
 class WMLog {
 public:
    static WMLog& GetInstance();
@@ -44,10 +56,12 @@ public:
    void LogError(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...);
    void LogWinError(const wchar_t *functionName, DWORD errorCode = -1);
 
-   void SetEnabled(bool enable);
+   void EnableLogFile(bool enable);
    bool IsEnabled() const;
    std::wstring GetLogFilePath();
 
+   std::vector<LogMessage> GetLogMessages() const;
+
 private:
    WMLog();
    ~WMLog();
@@ -57,7 +71,8 @@ private:
    void WriteMessage(const wchar_t *level, const wchar_t *msg);
    void DeleteLogFile();
 
-   std::mutex logMutex_;
+   mutable std::mutex logMutex_;
    bool enabled_;
    std::wofstream logFile_;
+   std::vector<LogMessage> logMessages_;
 };
index 1bdd332164ed346ccbdd3b02c4d8e83ad3a0f412..f5f2479aa80be59fc28ffb5e8cdd25f72353775c 100644 (file)
@@ -205,9 +205,9 @@ bool WinMute::Init()
    hAppIcon_ = LoadIconW(hglobInstance, MAKEINTRESOURCE(IDI_APP));
 
 #ifdef _DEBUG
-   WMLog::GetInstance().SetEnabled(true);
+   WMLog::GetInstance().EnableLogFile(true);
 #else
-   WMLog::GetInstance().SetEnabled(settings_.QueryValue(SettingsKey::LOGGING_ENABLED));
+   WMLog::GetInstance().EnableLogFile(settings_.QueryValue(SettingsKey::LOGGING_ENABLED));
 #endif
    log.LogInfo(L"Starting new session...");
 
index d6b706343bc15550d6bcccf042006a9a35bc1e49..ffa859d317c052ba170db764c7231671a1d80350 100644 (file)
@@ -245,6 +245,14 @@ BEGIN
     PUSHBUTTON      "Cancel",IDCANCEL,144,41,50,14
 END
 
+IDD_LOG DIALOGEX 0, 0, 307, 176
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
+CAPTION "WinMute Log"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    EDITTEXT        IDC_LOG_CONTENT,0,0,306,174,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -357,6 +365,14 @@ BEGIN
         TOPMARGIN, 7
         BOTTOMMARGIN, 55
     END
+
+    IDD_LOG, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 300
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 168
+    END
 END
 #endif    // APSTUDIO_INVOKED
 
@@ -432,6 +448,12 @@ BEGIN
     0
 END
 
+IDD_LOG AFX_DIALOG_LAYOUT
+BEGIN
+    0,
+    0, 0, 100, 100
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
index 7e19b6ec2018a4b92b3e90bd08a0d21819993d63..6e9c40006896e560eaed30317613b83ad7125688 100644 (file)
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
     </ClCompile>
+    <ClCompile Include="LogDialog.cpp" />
     <ClCompile Include="Settings_BluetoothDlg.cpp" />
     <ClCompile Include="Settings_ManageEndpointsDlg.cpp" />
     <ClCompile Include="Settings_MuteDlg.cpp" />
@@ -384,6 +385,14 @@ copy /Y %(FullPath) $(OutputPath)lang</Command>
       <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Copy translation "%(Filename)" to build directory</Message>
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutputPath)lang\%(Filename)%(Extension)</Outputs>
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutputPath)lang\%(Filename)%(Extension)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">mkdir $(OutputPath)lang &gt;nul 2&gt;&amp;1
+copy /Y %(FullPath) $(OutputPath)lang</Command>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">mkdir $(OutputPath)lang &gt;nul 2&gt;&amp;1
+copy /Y %(FullPath) $(OutputPath)lang</Command>
+      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Copy translation "%(Filename)" to build directory</Message>
+      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Copy translation "%(Filename)" to build directory</Message>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutputPath)lang\%(Filename)%(Extension)</Outputs>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutputPath)lang\%(Filename)%(Extension)</Outputs>
     </CustomBuild>
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
index 83e56e3558a37b5c27549d35efa0f91addeb0a8b..a5b7dbf1e4d7efbc48df3222a85610cf0c29d87e 100644 (file)
     <ClCompile Include="AboutDlg.cpp">
       <Filter>Source Files\UI\Dialogs\Settings</Filter>
     </ClCompile>
+    <ClCompile Include="LogDialog.cpp">
+      <Filter>Source Files\UI\Dialogs</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\Translations\lang-de.json">
index a616167f16f529129feee4dce0bac402979ae8d2..bbffeadbd6df30616935fca92080505d38880632 100644 (file)
@@ -25,6 +25,7 @@
 #define IDD_MANAGE_ENDPOINTS_ADD        137
 #define IDI_APP_UPDATE                  141
 #define IDI_APPUPDATE                   141
+#define IDD_LOG                         142
 #define IDC_LINK_HOMEPAGE               1001
 #define IDC_LINK_SUPPORT                1002
 #define IDC_LINK_PROJECT                1002
 #define IDC_UPDATES_VIA_PACKAGE_MANAGER_NOTICE 1072
 #define IDC_UPDATE_OPTIONS_DISABLED     1072
 #define IDC_LINK_HELP_TRANSLATING       1073
+#define IDC_EDIT1                       1075
+#define IDC_LOG_CONTENT                 1075
 #define ID_TRAYMENU_INFO                40001
 #define ID_TRAYMENU_                    40002
 #define ID_TRAYMENU_MUTEON              40003
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        142
+#define _APS_NEXT_RESOURCE_VALUE        144
 #define _APS_NEXT_COMMAND_VALUE         40041
-#define _APS_NEXT_CONTROL_VALUE         1074
+#define _APS_NEXT_CONTROL_VALUE         1076
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif