You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.6KB

  1. #pragma once
  2. #include <list>
  3. #include <common.hpp>
  4. namespace rack {
  5. /** Cross-platform functions for operating systems routines
  6. */
  7. namespace system {
  8. /** Returns a list of all entries (directories, files, symbols) in a directory.
  9. Sorted alphabetically.
  10. */
  11. std::list<std::string> getEntries(const std::string& path);
  12. std::list<std::string> getEntriesRecursive(const std::string &path, int depth);
  13. /** Returns whether the given path is a file. */
  14. bool isFile(const std::string& path);
  15. /** Returns whether the given path is a directory. */
  16. bool isDirectory(const std::string& path);
  17. /** Moves a file. */
  18. void moveFile(const std::string& srcPath, const std::string& destPath);
  19. /** Copies a file. */
  20. void copyFile(const std::string& srcPath, const std::string& destPath);
  21. /** Creates a directory.
  22. The parent directory must exist.
  23. */
  24. void createDirectory(const std::string& path);
  25. /** Creates all directories up to the path.
  26. */
  27. void createDirectories(const std::string& path);
  28. /** Deletes a directory.
  29. The directory must be empty. Fails silently.
  30. */
  31. void removeDirectory(const std::string& path);
  32. void removeDirectories(const std::string& path);
  33. /** Returns the number of logical simultaneous multithreading (SMT) (e.g. Intel Hyperthreaded) threads on the CPU. */
  34. int getLogicalCoreCount();
  35. /** Sets a name of the current thread for debuggers and OS-specific process viewers. */
  36. void setThreadName(const std::string& name);
  37. /** Returns the caller's human-readable stack trace with "\n"-separated lines. */
  38. std::string getStackTrace();
  39. /** Returns the current number of nanoseconds since the epoch.
  40. The goal of this function is to give the most precise (fine-grained) time available on the OS for benchmarking purposes, while being fast to compute.
  41. The epoch is undefined. Do not use this function to get absolute time, as it is different on each OS.
  42. */
  43. int64_t getNanoseconds();
  44. /** Opens a URL, also happens to work with PDFs and folders.
  45. Shell injection is possible, so make sure the URL is trusted or hard coded.
  46. May block, so open in a new thread.
  47. */
  48. void openBrowser(const std::string& url);
  49. /** Opens Windows Explorer, Finder, etc at the folder location. */
  50. void openFolder(const std::string& path);
  51. /** Runs an executable without blocking.
  52. The launched process will continue running if the current process is closed.
  53. */
  54. void runProcessDetached(const std::string& path);
  55. std::string getOperatingSystemInfo();
  56. /** Unzips a ZIP file to a folder.
  57. The folder must exist.
  58. Returns 0 if successful.
  59. */
  60. int unzipToFolder(const std::string& zipPath, const std::string& dir);
  61. } // namespace system
  62. } // namespace rack