hello,
liking systematic work, I was cleaning the unreadVariable warning from cppchecker.:-) This also let improve my programming knowledge and style...

Here a bunch of changes that touch only Win product,... that I am unable to test, having only unix.

Neverless, I did it would it be to reduce the warning noise (also some real coding error are popping out sometimes...) Could someone at least import and compile it with a Windows box?

By the way, just a question: from which version is Windows supported? some function names and comment let think me that some part could be deprecated.... ? (see example below)

Thanks and regards
Pierre-André

static BOOL MoveFileEx9x( LPCSTR lpExistingFileNameA, LPCSTR lpNewFileNameA, DWORD dwFlags )
{
    BOOL    fSuccess = FALSE;   // assume failure

    // Windows 9x has a special mechanism to move files after reboot
>From 54384140202fb9446b735d6bd5a08b351dc1a2b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre-Andr=C3=A9=20Jacquod?= <pjacq...@alumni.ethz.ch>
Date: Fri, 9 Sep 2011 21:58:21 +0200
Subject: [PATCH 6/6] [cppchecker] unreadVar warning - deleted unread variable

and simplified coding after that since the logic is not needed
anymore.
---
 .../customactions/shellextensions/vistaspecial.cxx |   60 ++------------------
 1 files changed, 5 insertions(+), 55 deletions(-)

diff --git a/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx b/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx
index aede073..40ff772 100644
--- a/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx
+++ b/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx
@@ -96,7 +96,6 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
 {
     bool bDirectoryRemoved = true;
 
-    std::_tstring mystr;
     std::_tstring sPattern = sPath + TEXT("\\") + TEXT("*.*");
     WIN32_FIND_DATA aFindData;
 
@@ -114,9 +113,6 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
         {
             std::_tstring sFileName = aFindData.cFileName;
 
-            mystr = "Current short file: " + sFileName;
-            // MessageBox(NULL, mystr.c_str(), "Current Content", MB_OK);
-
             if (( strcmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) &&
                 ( strcmp(sFileName.c_str(),sParentDir.c_str()) != 0 ))
             {
@@ -124,31 +120,11 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
 
                 if ( aFindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
                 {
-                    bool fSuccess = RemoveCompleteDirectory(sCompleteFileName);
-                    if ( fSuccess )
-                    {
-                        mystr = "Successfully removed content of dir " + sCompleteFileName;
-                        // MessageBox(NULL, mystr.c_str(), "Removed Directory", MB_OK);
-                    }
-                    else
-                    {
-                        mystr = "An error occurred during removing content of " + sCompleteFileName;
-                        // MessageBox(NULL, mystr.c_str(), "Error removing directory", MB_OK);
-                    }
+                    RemoveCompleteDirectory(sCompleteFileName);
                 }
                 else
                 {
-                    bool fSuccess = DeleteFile( sCompleteFileName.c_str() );
-                    if ( fSuccess )
-                    {
-                        mystr = "Successfully removed file " + sCompleteFileName;
-                        // MessageBox(NULL, mystr.c_str(), "Removed File", MB_OK);
-                    }
-                    else
-                    {
-                        mystr = "An error occurred during removal of file " + sCompleteFileName;
-                        // MessageBox(NULL, mystr.c_str(), "Error removing file", MB_OK);
-                    }
+                    DeleteFile( sCompleteFileName.c_str() );
                 }
             }
 
@@ -162,17 +138,9 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
         // RemoveDirectory is only successful, if the last handle to the directory is closed
         // -> first removing content -> closing handle -> remove empty directory
 
-        bool fRemoveDirSuccess = RemoveDirectory(sPath.c_str());
 
-        if ( fRemoveDirSuccess )
-        {
-            mystr = "Successfully removed dir " + sPath;
-            // MessageBox(NULL, mystr.c_str(), "Removed Directory", MB_OK);
-        }
-        else
+        if( !( RemoveDirectory(sPath.c_str()) ) )
         {
-            mystr = "An error occurred during removal of empty directory " + sPath;
-            // MessageBox(NULL, mystr.c_str(), "Error removing directory", MB_OK);
             bDirectoryRemoved = false;
         }
     }
@@ -189,8 +157,6 @@ extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle )
     std::_tstring sRenameSrc = sOfficeInstallPath + TEXT("program");
     std::_tstring sRenameDst = sOfficeInstallPath + TEXT("program_old");
 
-//    MessageBox(NULL, sRenameSrc.c_str(), "INSTALLLOCATION", MB_OK);
-
     bool bSuccess = MoveFile( sRenameSrc.c_str(), sRenameDst.c_str() );
     if ( !bSuccess )
     {
@@ -205,13 +171,6 @@ extern "C" UINT __stdcall RenamePrgFolder( MSIHANDLE handle )
         }
     }
 
-#if 0
-    if ( !bSuccess )
-        MessageBox(NULL, "Renaming folder failed", "RenamePrgFolder", MB_OK);
-    else
-        MessageBox(NULL, "Renaming folder successful", "RenamePrgFolder", MB_OK);
-#endif
-
     return ERROR_SUCCESS;
 }
 
@@ -220,25 +179,16 @@ extern "C" UINT __stdcall RemovePrgFolder( MSIHANDLE handle )
     std::_tstring sOfficeInstallPath = GetMsiProperty(handle, TEXT("INSTALLLOCATION"));
     std::_tstring sRemoveDir = sOfficeInstallPath + TEXT("program_old");
 
-//    MessageBox(NULL, sRemoveDir.c_str(), "REMOVING OLD DIR", MB_OK);
-
-    bool bSuccess = RemoveCompleteDirectory( sRemoveDir );
+    RemoveCompleteDirectory( sRemoveDir );
 
     TCHAR sAppend[2] = TEXT("0");
     for ( int i = 0; i < 10; i++ )
     {
         sRemoveDir = sOfficeInstallPath + TEXT("program_old") + sAppend;
-        bSuccess = RemoveCompleteDirectory( sRemoveDir );
+        RemoveCompleteDirectory( sRemoveDir );
         sAppend[0] += 1;
     }
 
-#if 0
-    if ( bSuccess )
-        MessageBox(NULL, "Removing folder successful", "RemovePrgFolder", MB_OK);
-    else
-        MessageBox(NULL, "Removing folder failed", "RemovePrgFolder", MB_OK);
-#endif
-
     return ERROR_SUCCESS;
 }
 
-- 
1.7.3.4

>From 83021530419f9785205e0c349da9f2299f0b7104 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre-Andr=C3=A9=20Jacquod?= <pjacq...@alumni.ethz.ch>
Date: Fri, 9 Sep 2011 21:52:22 +0200
Subject: [PATCH 5/6] [cppchecker] unreadVar warning - unneded variable deleted

After deleting the different assignment that were not used, some
part of the code could be simiplified, since there is no need
any more for the logic
---
 .../shellextensions/registerextensions.cxx         |   34 ++------------------
 1 files changed, 3 insertions(+), 31 deletions(-)

diff --git a/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx b/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx
index 28ea399..9435118 100644
--- a/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx
+++ b/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx
@@ -117,7 +117,6 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
 {
     bool bDirectoryRemoved = true;
 
-    std::_tstring mystr;
     std::_tstring sPattern = sPath + TEXT("\\") + TEXT("*.*");
     WIN32_FIND_DATA aFindData;
 
@@ -135,8 +134,6 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
             std::_tstring sCurrentDir = TEXT(".");
             std::_tstring sParentDir = TEXT("..");
 
-            mystr = "Current short file: " + sFileName;
-
             if (( strcmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) &&
                 ( strcmp(sFileName.c_str(),sParentDir.c_str()) != 0 ))
             {
@@ -144,27 +141,11 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
 
                 if ( aFindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
                 {
-                    bool fSuccess = RemoveCompleteDirectory(sCompleteFileName);
-                    if ( fSuccess )
-                    {
-                        mystr = "Successfully removed content of dir " + sCompleteFileName;
-                    }
-                    else
-                    {
-                        mystr = "An error occurred during removing content of " + sCompleteFileName;
-                    }
+                    RemoveCompleteDirectory(sCompleteFileName);
                 }
                 else
                 {
-                    bool fSuccess = DeleteFile( sCompleteFileName.c_str() );
-                    if ( fSuccess )
-                    {
-                        mystr = "Successfully removed file " + sCompleteFileName;
-                    }
-                    else
-                    {
-                        mystr = "An error occurred during removal of file " + sCompleteFileName;
-                    }
+                    DeleteFile( sCompleteFileName.c_str() );
                 }
             }
 
@@ -178,17 +159,8 @@ static BOOL RemoveCompleteDirectory( std::_tstring sPath )
         // RemoveDirectory is only successful, if the last handle to the directory is closed
         // -> first removing content -> closing handle -> remove empty directory
 
-        bool fRemoveDirSuccess = RemoveDirectory(sPath.c_str());
-
-        if ( fRemoveDirSuccess )
-        {
-            mystr = "Successfully removed dir " + sPath;
-            // MessageBox(NULL, mystr.c_str(), "Removed Directory", MB_OK);
-        }
-        else
+        if ( ! ( RemoveDirectory(sPath.c_str()) ) )
         {
-            mystr = "An error occurred during removal of empty directory " + sPath;
-            // MessageBox(NULL, mystr.c_str(), "Error removing directory", MB_OK);
             bDirectoryRemoved = false;
         }
     }
-- 
1.7.3.4

>From da8dacce014b494a0b3a7cd3bb94768e00a9d1f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre-Andr=C3=A9=20Jacquod?= <pjacq...@alumni.ethz.ch>
Date: Fri, 9 Sep 2011 21:34:32 +0200
Subject: [PATCH 4/6] [cppchecker] unreadVar warning - deleted unneded variable

Also deleted a part of the code that did nothing, just defining
variable and reading them as argument.
---
 desktop/win32/source/applauncher/launcher.cxx |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/desktop/win32/source/applauncher/launcher.cxx b/desktop/win32/source/applauncher/launcher.cxx
index a7a17b5..fd8edb1 100644
--- a/desktop/win32/source/applauncher/launcher.cxx
+++ b/desktop/win32/source/applauncher/launcher.cxx
@@ -67,11 +67,6 @@ extern "C" int APIENTRY _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
 
     LPTSTR  lpCommandLine = GetCommandLine();
 
-    LPTSTR  *ppArguments = NULL;
-    int     nArguments = 0;
-
-    ppArguments = GetArgv( &nArguments );
-
     {
         lpCommandLine = (LPTSTR)_alloca( sizeof(_TCHAR) * (_tcslen(lpCommandLine) + _tcslen(APPLICATION_SWITCH) + 2) );
 
-- 
1.7.3.4

>From fba9ae5da83ff55e23a9eff1b9af3eb6a65bc92d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre-Andr=C3=A9=20Jacquod?= <pjacq...@alumni.ethz.ch>
Date: Fri, 9 Sep 2011 21:30:04 +0200
Subject: [PATCH 3/6] [cppchecker] unreadVar warning - deleted unneded variable

no used, since part of the coding commented since 2005
---
 .../shellextensions/migrateinstallpath.cxx         |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx b/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx
index a487309..395a21f 100644
--- a/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx
+++ b/setup_native/source/win32/customactions/shellextensions/migrateinstallpath.cxx
@@ -86,10 +86,6 @@ extern "C" UINT __stdcall MigrateInstallPath( MSIHANDLE handle )
     std::_tstring   sProductKey = "Software\\" + sManufacturer + "\\" + sDefinedName +
                                         "\\" + sUpdateVersion + "\\" + sUpgradeCode;
 
-    std::_tstring   mystr;
-    mystr = "ProductKey: " + sProductKey;
-    // MessageBox( NULL, mystr.c_str(), "ProductKey", MB_OK );
-
     if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER,  sProductKey.c_str(), &hKey ) )
     {
         if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) )
-- 
1.7.3.4

>From 5f4f4360b216187fa9508947074d1ec80b95a9ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre-Andr=C3=A9=20Jacquod?= <pjacq...@alumni.ethz.ch>
Date: Fri, 9 Sep 2011 21:26:21 +0200
Subject: [PATCH 2/6] [cppchecker] unreadVar warning - deletion of unneded variable

---
 .../win32/customactions/patch/swappatchfiles.cxx   |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/setup_native/source/win32/customactions/patch/swappatchfiles.cxx b/setup_native/source/win32/customactions/patch/swappatchfiles.cxx
index db7fbeb..5028a5f 100644
--- a/setup_native/source/win32/customactions/patch/swappatchfiles.cxx
+++ b/setup_native/source/win32/customactions/patch/swappatchfiles.cxx
@@ -691,7 +691,6 @@ extern "C" UINT __stdcall IsOfficeRunning( MSIHANDLE handle )
 
 extern "C" UINT __stdcall SetFeatureState( MSIHANDLE handle )
 {
-    std::_tstring   mystr;
 
     // 1. Reading Product Code from setup.ini of installed Office
 
@@ -719,7 +718,6 @@ extern "C" UINT __stdcall SetFeatureState( MSIHANDLE handle )
 
     std::_tstring productCode = TEXT(szProductCode);
     productCode = ConvertGuid(std::_tstring(productCode.c_str() + 1, productCode.length() - 2));
-    mystr = TEXT("Changed product code: ") + productCode;
 
     // 3. Setting path in the Windows registry to find installed features
 
@@ -730,13 +728,11 @@ extern "C" UINT __stdcall SetFeatureState( MSIHANDLE handle )
     {
         registryRoot = HKEY_LOCAL_MACHINE;
         registryKey = TEXT("Software\\Classes\\Installer\\Features\\") + productCode;
-        mystr = registryKey;
     }
     else
     {
         registryRoot = HKEY_CURRENT_USER;
         registryKey = TEXT("Software\\Microsoft\\Installer\\Features\\") + productCode;
-        mystr = registryKey;
     }
 
     // 4. Collecting all installed features from Windows registry
@@ -760,7 +756,6 @@ extern "C" UINT __stdcall SetFeatureState( MSIHANDLE handle )
             if ( ERROR_SUCCESS == lEnumResult )
             {
                 std::_tstring sValueName = szValueName;
-                std::_tstring sValueData = szValueData;
 
                 // Does this feature exist in this patch?
                 if ( IsSetMsiProperty(handle, sValueName) )
-- 
1.7.3.4

>From 2ec8232cf3139816ad7ad90ed3bca8fe53c4b2c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre-Andr=C3=A9=20Jacquod?= <pjacq...@alumni.ethz.ch>
Date: Fri, 9 Sep 2011 20:55:53 +0200
Subject: [PATCH 1/6] [cppchecker] unreadVar warning - deletion of unneded variable

---
 fpicker/source/win32/filepicker/previewadapter.cxx |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fpicker/source/win32/filepicker/previewadapter.cxx b/fpicker/source/win32/filepicker/previewadapter.cxx
index 51eb8b5..fcd7ea3 100644
--- a/fpicker/source/win32/filepicker/previewadapter.cxx
+++ b/fpicker/source/win32/filepicker/previewadapter.cxx
@@ -317,11 +317,11 @@ void SAL_CALL CPreviewAdapterImpl::rearrangeLayout()
 
         // resize the filelistbox to the half of the
         // available space
-        bool bRet = SetWindowPos(flb_new,
+        SetWindowPos(flb_new,
             NULL, 0, 0, cx, height,
             SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 
-        bRet = SetWindowPos(flb_old,
+        SetWindowPos(flb_old,
             NULL, 0, 0, cx, height,
             SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
 
-- 
1.7.3.4

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to