utility.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
  3. * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
  4. * Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #pragma once
  21. #include "NCTools.h"
  22. namespace NCTools {
  23. typedef std::variant<int, std::wstring, std::vector<unsigned char>> registryVariant;
  24. static const std::wstring PathSeparator = L"\\";
  25. namespace Utility {
  26. // Ported from libsync
  27. registryVariant registryGetKeyValue(HKEY hRootKey, const std::wstring& subKey, const std::wstring& valueName);
  28. bool registrySetKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName, DWORD type, const registryVariant &value);
  29. bool registryDeleteKeyTree(HKEY hRootKey, const std::wstring &subKey);
  30. bool registryDeleteKeyValue(HKEY hRootKey, const std::wstring &subKey, const std::wstring &valueName);
  31. bool registryWalkSubKeys(HKEY hRootKey, const std::wstring &subKey, const std::function<void(HKEY, const std::wstring&)> &callback);
  32. // Ported from gui, modified to optionally rename matching files
  33. typedef std::function<void(const std::wstring&, std::wstring&)> copy_dir_recursive_callback;
  34. bool copy_dir_recursive(std::wstring from_dir, std::wstring to_dir, copy_dir_recursive_callback* callbackFileNameMatchReplace = nullptr);
  35. // Created for native Win32
  36. DWORD execCmd(std::wstring cmd, bool wait = true);
  37. bool killProcess(const std::wstring &exePath);
  38. bool isValidDirectory(const std::wstring &path);
  39. std::wstring getAppRegistryString(const std::wstring &appVendor, const std::wstring &appName, const std::wstring &valueName);
  40. std::wstring getAppPath(const std::wstring &appVendor, const std::wstring &appName);
  41. std::wstring getConfigPath(const std::wstring &appName);
  42. void waitForNsisUninstaller(const std::wstring& appShortName);
  43. void removeNavigationPaneEntries(const std::wstring &appName);
  44. }
  45. } // namespace NCTools