[Libreoffice-commits] core.git: desktop/win32

Deb Barkley-Yeung (via logerrit) logerrit at kemper.freedesktop.org
Mon Nov 30 09:36:18 UTC 2020


 desktop/win32/source/loader.cxx |   54 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)

New commits:
commit 7f477f8dd85c84c9c1a9e673b685dc0e03d1d45a
Author:     Deb Barkley-Yeung <dbarkleyyeung at gmail.com>
AuthorDate: Sun Nov 22 21:57:23 2020 -0800
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Nov 30 10:35:37 2020 +0100

    tdf#48413 handle wildcards on Windows
    
    Since Windows doesn't handle wildcards on the command line, handle
    wildcards manually.
    
    Change-Id: I8c61ad77184827237edb3722183bf4a0b9a480a7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106393
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/desktop/win32/source/loader.cxx b/desktop/win32/source/loader.cxx
index 3adf34aa3043..82b323d7c772 100644
--- a/desktop/win32/source/loader.cxx
+++ b/desktop/win32/source/loader.cxx
@@ -77,6 +77,25 @@ std::wstring EscapeArg(LPCWSTR sArg)
     return sResult;
 }
 
+void AddEscapedArg(LPCWSTR sArg, std::vector<std::wstring>& aEscapedArgs,
+                   std::size_t& iLengthAccumulator)
+{
+    std::wstring sEscapedArg = EscapeArg(sArg);
+    aEscapedArgs.push_back(sEscapedArg);
+    iLengthAccumulator += sEscapedArg.length() + 1; // a space between args
+}
+
+bool HasWildCard(LPCWSTR sArg)
+{
+    while (*sArg != L'\0')
+    {
+        if (*sArg == L'*' || *sArg == L'?')
+            return true;
+        sArg++;
+    }
+    return false;
+}
+
 }
 
 namespace desktop_win32 {
@@ -214,9 +233,38 @@ int officeloader_impl(bool bAllowConsole)
             std::size_t n = 0;
             for (int i = 0; i < argc; ++i)
             {
-                std::wstring sEscapedArg = EscapeArg(argv[i]);
-                aEscapedArgs.push_back(sEscapedArg);
-                n += sEscapedArg.length() + 1; // a space between args
+                // check for wildCards in arguments- windows does not expand automatically
+                if (HasWildCard(argv[i]))
+                {
+                    WIN32_FIND_DATAW aFindData;
+                    HANDLE h = FindFirstFileW(argv[i], &aFindData);
+                    if (h == INVALID_HANDLE_VALUE)
+                    {
+                        AddEscapedArg(argv[i], aEscapedArgs, n);
+                    }
+                    else
+                    {
+                        const int nPathSize = 32 * 1024;
+                        wchar_t drive[nPathSize];
+                        wchar_t dir[nPathSize];
+                        wchar_t path[nPathSize];
+                        _wsplitpath_s(argv[i], drive, nPathSize, dir, nPathSize, nullptr, 0,
+                                      nullptr, 0);
+                        _wmakepath_s(path, nPathSize, drive, dir, aFindData.cFileName, nullptr);
+                        AddEscapedArg(path, aEscapedArgs, n);
+
+                        while (FindNextFileW(h, &aFindData))
+                        {
+                            _wmakepath_s(path, nPathSize, drive, dir, aFindData.cFileName, nullptr);
+                            AddEscapedArg(path, aEscapedArgs, n);
+                        }
+                        FindClose(h);
+                    }
+                }
+                else
+                {
+                    AddEscapedArg(argv[i], aEscapedArgs, n);
+                }
             }
             LocalFree(argv);
             n += MY_LENGTH(L" \"-env:OOO_CWD=2") + 4 * cwdLen + MY_LENGTH(L"\"") + 1;


More information about the Libreoffice-commits mailing list