opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
os.h
Go to the documentation of this file.
1#pragma once
2
3#include <ctime>
4#include <filesystem>
5#include <fstream>
6#include <string_view>
7#include <string>
8#include <utility>
9
10// os: where all the icky OS/distro/filesystem-specific stuff is hidden
11namespace osc
12{
13 // returns local system time as a calendar date and time broken down into its components.
15
16 // returns the full path to the currently-executing application
17 //
18 // care: can be slow: downstream callers should cache it
19 std::filesystem::path current_executable_directory();
20
21 // returns the full path to the user's data directory
22 std::filesystem::path user_data_directory(
23 std::string_view organization_name,
24 std::string_view application_name
25 );
26
27 // tries to open the specified filepath in the OS's default application for opening
28 // a path (usually, based on its extension)
29 //
30 // - this function returns immediately: the application is opened in a separate
31 // window
32 //
33 // - how, or what, the OS does is implementation-defined. E.g. on Windows, this
34 // opens the path by searching the file's extension against a list of default
35 // applications or, if Windows detects it's a URL, it will open the URL in
36 // the user's default web browser, etc.
37 void open_file_in_os_default_application(const std::filesystem::path&);
38
39 // tries to open the specified URL in the OS's default browser
40 void open_url_in_os_default_web_browser(std::string_view);
41
42 // returns the contents of the clipboard as text, or an empty string if nothing's in the clipboard
43 std::string get_clipboard_text();
44
45 // returns `true` if `content` was successfully copied to the user's clipboard
46 bool set_clipboard_text(std::string_view);
47
48 // creates a temporary file in the most secure manner possible. There are no race conditions
49 // in the file's creation - assuming that the operating system properly implements the `os.O_EXCL`
50 // flag
51 //
52 // the caller is responsible for deleting the temporary file once it is no longer needed
53 //
54 // returns an open handle to the file (opened with `w+b`) and the absolute path to the temporary file
55 std::pair<std::fstream, std::filesystem::path> mkstemp(
56 std::string_view suffix = {},
57 std::string_view prefix = {}
58 );
59
60 // Creates a temporary directory in the most secure manner possible.
61 //
62 // The caller is responsible for deleting the temporary directory once it is no longer needed.
63 std::filesystem::path mkdtemp(
64 std::string_view suffix = {},
65 std::string_view prefix = {}
66 );
67}
Definition custom_decoration_generator.h:5
std::pair< std::fstream, std::filesystem::path > mkstemp(std::string_view suffix={}, std::string_view prefix={})
std::filesystem::path mkdtemp(std::string_view suffix={}, std::string_view prefix={})
bool set_clipboard_text(std::string_view)
std::tm system_calendar_time()
std::filesystem::path user_data_directory(std::string_view organization_name, std::string_view application_name)
std::string get_clipboard_text()
std::filesystem::path current_executable_directory()
void open_url_in_os_default_web_browser(std::string_view)
void open_file_in_os_default_application(const std::filesystem::path &)