forked from WinMerge/winmerge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,240 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/** | ||
* @file ClipboardHistory.cpp | ||
* | ||
* @brief Implementation for Clipboard history functions | ||
*/ | ||
|
||
#include "StdAfx.h" | ||
#include "ClipboardHistory.h" | ||
#include "ClipBoard.h" | ||
#include "Concurrent.h" | ||
#include "UniFile.h" | ||
|
||
#ifdef _WIN64 | ||
|
||
#include <winrt/windows.foundation.collections.h> | ||
#include <winrt/windows.applicationmodel.datatransfer.h> | ||
#include <winrt/windows.graphics.imaging.h> | ||
#include <winrt/windows.storage.streams.h> | ||
|
||
using namespace winrt::Windows::ApplicationModel::DataTransfer; | ||
using namespace winrt::Windows::Graphics::Imaging; | ||
using namespace winrt::Windows::Storage; | ||
|
||
#endif | ||
|
||
namespace ClipboardHistory | ||
{ | ||
namespace impl | ||
{ | ||
std::shared_ptr<TempFile> CreateTempTextFile(const String& text) | ||
{ | ||
std::shared_ptr<TempFile> pTempFile(new TempFile()); | ||
pTempFile->Create(_T("CLP"), L".txt"); | ||
String path = pTempFile->GetPath(); | ||
UniStdioFile file; | ||
if (file.OpenCreateUtf8(path)) | ||
{ | ||
file.WriteString(text); | ||
file.Close(); | ||
} | ||
return pTempFile; | ||
} | ||
|
||
String GetClipboardText() | ||
{ | ||
String text; | ||
GetFromClipboard(text, nullptr); | ||
return text; | ||
} | ||
|
||
#ifdef _WIN64 | ||
std::shared_ptr<TempFile> CreateTempBitmapFile(const DataPackageView& dataPackageView) | ||
{ | ||
std::shared_ptr<TempFile> pTempFile(new TempFile()); | ||
pTempFile->Create(_T("CLP"), _T(".png")); | ||
|
||
auto streamReference = dataPackageView.GetBitmapAsync().get(); | ||
auto inputStream = streamReference.OpenReadAsync().get(); | ||
auto decoder = BitmapDecoder::CreateAsync(inputStream).get(); | ||
auto bitmap = decoder.GetSoftwareBitmapAsync().get(); | ||
|
||
auto outputFile = StorageFile::GetFileFromPathAsync(pTempFile->GetPath()).get(); | ||
auto outputStream = outputFile.OpenAsync(FileAccessMode::ReadWrite).get(); | ||
auto encoder = BitmapEncoder::CreateAsync(BitmapEncoder::PngEncoderId(), outputStream).get(); | ||
encoder.SetSoftwareBitmap(bitmap); | ||
encoder.FlushAsync().get(); | ||
|
||
return pTempFile; | ||
} | ||
#endif | ||
|
||
std::vector<Item> GetItems(unsigned num) | ||
{ | ||
std::vector<Item> result; | ||
#ifdef _WIN64 | ||
try | ||
{ | ||
auto historyItems = Clipboard::GetHistoryItemsAsync().get(); | ||
auto items = historyItems.Items(); | ||
for (unsigned int i = 0; i < num; ++i) | ||
{ | ||
result.emplace_back(); | ||
auto& item = result.back(); | ||
if (i < items.Size()) | ||
{ | ||
try | ||
{ | ||
auto dataPackageView = items.GetAt(i).Content(); | ||
item.timestamp = winrt::clock::to_time_t(items.GetAt(i).Timestamp()); | ||
if (dataPackageView.Contains(StandardDataFormats::Text())) | ||
{ | ||
item.pTextTempFile = CreateTempTextFile(dataPackageView.GetTextAsync().get().c_str()); | ||
} | ||
if (dataPackageView.Contains(StandardDataFormats::Bitmap())) | ||
{ | ||
item.pBitmapTempFile = CreateTempBitmapFile(dataPackageView); | ||
} | ||
if (!item.pTextTempFile && !item.pBitmapTempFile) | ||
{ | ||
item.pTextTempFile = CreateTempTextFile(_T("")); | ||
} | ||
} | ||
catch (const winrt::hresult_error& e) | ||
{ | ||
item.pTextTempFile = CreateTempTextFile(e.message().c_str()); | ||
} | ||
} | ||
else | ||
{ | ||
if (i == 0) | ||
time(&item.timestamp); | ||
item.pTextTempFile = CreateTempTextFile(i == 0 ? | ||
GetClipboardText() : | ||
(!Clipboard::IsHistoryEnabled() ? _("Clipboard history is disabled.\r\nTo enable clipboard history, press Windows logo key + V and then click the Turn on button.") : _T(""))); | ||
} | ||
} | ||
} | ||
catch (const winrt::hresult_error&) | ||
{ | ||
for (unsigned int i = 0; i < num; ++i) | ||
{ | ||
result.emplace_back(); | ||
auto& item = result.back(); | ||
if (i == 0) | ||
time(&item.timestamp); | ||
item.pTextTempFile = CreateTempTextFile( | ||
i == 0 ? GetClipboardText() : _("This system does not support clipboard history.")); | ||
} | ||
} | ||
#else | ||
for (unsigned int i = 0; i < num; ++i) | ||
{ | ||
result.emplace_back(); | ||
auto& item = result.back(); | ||
if (i == 0) | ||
time(&item.timestamp); | ||
item.pTextTempFile = CreateTempTextFile( | ||
i == 0 ? GetClipboardText() : _("The 32-bit version of WinMerge does not support Clipboard Compare")); | ||
} | ||
#endif | ||
return result; | ||
} | ||
} | ||
|
||
std::vector<Item> GetItems(unsigned num) | ||
{ | ||
auto task = Concurrent::CreateTask([num] { | ||
return impl::GetItems(num); | ||
}); | ||
return task.Get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @file ClipboardHistory.h | ||
* | ||
* @brief Declaration file for Clipboard history functions | ||
*/ | ||
#pragma once | ||
|
||
#include "UnicodeString.h" | ||
#include "TempFile.h" | ||
#include <memory> | ||
#include <vector> | ||
#include <ctime> | ||
|
||
namespace ClipboardHistory | ||
{ | ||
struct Item | ||
{ | ||
time_t timestamp; | ||
std::shared_ptr<TempFile> pTextTempFile; | ||
std::shared_ptr<TempFile> pBitmapTempFile; | ||
}; | ||
std::vector<Item> GetItems(unsigned num); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.