[ZIPFLDR] Various usability improvements
authorMark Jansen <mark.jansen@reactos.org>
Sat, 21 Apr 2018 10:50:05 +0000 (12:50 +0200)
committerMark Jansen <mark.jansen@reactos.org>
Sun, 22 Apr 2018 15:38:44 +0000 (17:38 +0200)
- Take the user-entered folder into account
- Hide size / ratio for folders
CORE-14543
CORE-14542

dll/shellext/zipfldr/CZipExtract.cpp
dll/shellext/zipfldr/CZipFolder.hpp
dll/shellext/zipfldr/zippidl.cpp

index 0b5465a..258f9b3 100644 (file)
@@ -12,10 +12,12 @@ class CZipExtract :
 {
     CStringW m_Filename;
     CStringW m_Directory;
+    bool m_DirectoryChanged;
     unzFile uf;
 public:
     CZipExtract(PCWSTR Filename)
-        :uf(NULL)
+        :m_DirectoryChanged(false)
+        ,uf(NULL)
     {
         m_Filename = Filename;
         m_Directory = m_Filename;
@@ -158,6 +160,7 @@ public:
         int OnSetActive()
         {
             SetDlgItemTextW(IDC_DIRECTORY, m_pExtract->m_Directory);
+            m_pExtract->m_DirectoryChanged = false;
             ::EnableWindow(GetDlgItem(IDC_PASSWORD), FALSE);    /* Not supported for now */
             GetParent().CenterWindow(::GetDesktopWindow());
             return 0;
@@ -169,6 +172,9 @@ public:
             ::EnableWindow(GetDlgItem(IDC_DIRECTORY), FALSE);
             ::EnableWindow(GetDlgItem(IDC_PASSWORD), FALSE);
 
+            if (m_pExtract->m_DirectoryChanged)
+                UpdateDirectory();
+
             if (!m_pExtract->Extract(m_hWnd, GetDlgItem(IDC_PROGRESS)))
             {
                 /* Extraction failed, do not go to the next page */
@@ -211,6 +217,9 @@ public:
             CStringW title(MAKEINTRESOURCEW(IDS_WIZ_BROWSE_TITLE));
             bi.lpszTitle = title;
 
+            if (m_pExtract->m_DirectoryChanged)
+                UpdateDirectory();
+
             browse_info info = { m_hWnd, m_pExtract->m_Directory.GetString() };
             bi.lParam = (LPARAM)&info;
 
@@ -222,21 +231,35 @@ public:
             {
                 m_pExtract->m_Directory = tmpPath;
                 SetDlgItemTextW(IDC_DIRECTORY, m_pExtract->m_Directory);
+                m_pExtract->m_DirectoryChanged = false;
             }
             return 0;
         }
 
+        LRESULT OnEnChangeDirectory(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
+        {
+            m_pExtract->m_DirectoryChanged = true;
+            return 0;
+        }
+
         LRESULT OnPassword(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
         {
             return 0;
         }
 
+        void UpdateDirectory()
+        {
+            GetDlgItemText(IDC_DIRECTORY, m_pExtract->m_Directory);
+            m_pExtract->m_DirectoryChanged = false;
+        }
+
     public:
         enum { IDD = IDD_PROPPAGEDESTINATION };
 
         BEGIN_MSG_MAP(CCompleteSettingsPage)
             COMMAND_ID_HANDLER(IDC_BROWSE, OnBrowse)
             COMMAND_ID_HANDLER(IDC_PASSWORD, OnPassword)
+            COMMAND_HANDLER(IDC_DIRECTORY, EN_CHANGE, OnEnChangeDirectory)
             CHAIN_MSG_MAP(CPropertyPageImpl<CExtractSettingsPage>)
         END_MSG_MAP()
     };
@@ -319,6 +342,7 @@ public:
         if (err != UNZ_OK)
         {
             DPRINT1("ERROR, unzGetGlobalInfo64: 0x%x\n", err);
+            Close();
             return false;
         }
 
@@ -326,6 +350,7 @@ public:
         if (!zipEnum.initialize(this))
         {
             DPRINT1("ERROR, zipEnum.initialize\n");
+            Close();
             return false;
         }
 
@@ -351,6 +376,7 @@ public:
             HRESULT hr = SHPathPrepareForWriteA(hDlg, NULL, FullPath, dwFlags);
             if (FAILED_UNEXPECTEDLY(hr))
             {
+                Close();
                 return false;
             }
             CurrentFile++;
@@ -363,6 +389,7 @@ public:
             if (err != UNZ_OK)
             {
                 DPRINT1("ERROR, unzOpenCurrentFilePassword: 0x%x\n", err);
+                Close();
                 return false;
             }
 
@@ -386,6 +413,8 @@ public:
                         case CConfirmReplace::No:
                             break;
                         case CConfirmReplace::Cancel:
+                            unzCloseCurrentFile(uf);
+                            Close();
                             return false;
                         }
                     }
@@ -408,6 +437,7 @@ public:
                 {
                     unzCloseCurrentFile(uf);
                     DPRINT1("ERROR, CreateFileA: 0x%x (%s)\n", dwErr, bOverwriteAll ? "Y" : "N");
+                    Close();
                     return false;
                 }
             }
@@ -454,6 +484,7 @@ public:
             {
                 unzCloseCurrentFile(uf);
                 DPRINT1("ERROR, unzReadCurrentFile2: 0x%x\n", err);
+                Close();
                 return false;
             }
             else
index fa98673..2b7010c 100644 (file)
@@ -172,6 +172,9 @@ public:
         case 2: /* Compressed size */
         case 4: /* Size */
         {
+            if (isDir)
+                return SHSetStrRet(&psd->str, L"");
+
             ULONG64 Size = iColumn == 2 ? zipEntry->CompressedSize : zipEntry->UncompressedSize;
             if (!StrFormatByteSizeW(Size, Buffer, _countof(Buffer)))
                 return E_FAIL;
@@ -183,8 +186,11 @@ public:
             return SHSetStrRet(&psd->str, _AtlBaseModule.GetResourceInstance(), zipEntry->Password ? IDS_YES : IDS_NO);
         case 5: /* Ratio */
         {
+            if (isDir)
+                return SHSetStrRet(&psd->str, L"");
+
             int ratio = 0;
-            if (zipEntry->UncompressedSize && !isDir)
+            if (zipEntry->UncompressedSize)
                 ratio = 100 - (int)((zipEntry->CompressedSize*100)/zipEntry->UncompressedSize);
             StringCchPrintfW(Buffer, _countof(Buffer), L"%d%%", ratio);
             return SHSetStrRet(&psd->str, Buffer);
index 1e1eb9f..79b23c3 100644 (file)
@@ -14,6 +14,8 @@ LPITEMIDLIST _ILCreate(ZipPidlType Type, LPCSTR lpString, unz_file_info64& info)
     if (!pidl)
         return NULL;
 
+    ZeroMemory(pidl, cbData + sizeof(WORD));
+
     pidl->cb = cbData;
     pidl->MagicType = 'z';
     pidl->ZipType = Type;