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