forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPC.cpp
More file actions
62 lines (51 loc) · 1.21 KB
/
IPC.cpp
File metadata and controls
62 lines (51 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "pch.h"
#include "IPC.h"
#include "Constants.h"
#include <common/SettingsAPI/settings_helpers.h>
constexpr DWORD DefaultPipeBufferSize = 8192;
constexpr DWORD DefaultPipeTimeoutMillis = 200;
namespace ipc
{
Writer::Writer()
{
start();
}
Writer::~Writer()
{
finish();
}
HRESULT Writer::start()
{
std::wstring path = PTSettingsHelper::get_module_save_folder_location(constants::nonlocalizable::PowerToyName);
path += L"\\";
path += constants::nonlocalizable::LastRunPath;
try
{
m_stream = std::ofstream(path);
return S_OK;
}
catch (...)
{
return E_FAIL;
}
}
HRESULT Writer::add_path(LPCWSTR path)
{
int length = lstrlenW(path);
if (!m_stream.write(reinterpret_cast<const char*>(path), length * sizeof(WCHAR)))
{
return E_FAIL;
}
WCHAR line_break = L'\n';
if (!m_stream.write(reinterpret_cast<const char*>(&line_break), sizeof(WCHAR)))
{
return E_FAIL;
}
return S_OK;
}
void Writer::finish()
{
add_path(L"");
m_stream.close();
}
}