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.

70 lines
2.5KB

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