Skip to content

Commit

Permalink
2.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
xland committed Jun 13, 2024
1 parent 4a25fe1 commit c88b946
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
3 changes: 3 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ Whether there is any topic to talk about, whether it is related to this product

This project is under the [MIT license](./licence).


## Stargazers over time
[![Stargazers over time](https://starchart.cc/xland/ScreenCapture.svg?variant=adaptive)](https://starchart.cc/xland/ScreenCapture)
8 changes: 4 additions & 4 deletions res/res.rc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ IDI_LOGO ICON "logo.ico"
IDR_ICON_FONT ICON_FONT "icon.ttf"

VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,1,8,0
PRODUCTVERSION 2,1,8,0
FILEVERSION 2,1,9,0
PRODUCTVERSION 2,1,9,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -26,12 +26,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "GitHub xland"
VALUE "FileDescription", "ScreenCapture"
VALUE "FileVersion", "2.1.8.0"
VALUE "FileVersion", "2.1.9.0"
VALUE "InternalName", "ScreenCapture.exe"
VALUE "LegalCopyright", "Copyright (C) LiuXiaolun 2023-2024"
VALUE "OriginalFilename", "ScreenCapture.exe"
VALUE "ProductName", "ScreenCapture"
VALUE "ProductVersion", "2.1.8.0"
VALUE "ProductVersion", "2.1.9.0"
END
END
BLOCK "VarFileInfo"
Expand Down
41 changes: 32 additions & 9 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Windows.h>
#include <shlobj.h>
#include <sstream>
#include <filesystem>
#include "include/core/SkFont.h"
#include "include/core//SkFontMgr.h"
#include "include/core/SkFontStyle.h"
Expand All @@ -24,6 +25,7 @@ WindowBase* win { nullptr };
static int exitCode{ 0 };
static std::vector<std::shared_ptr<SkRect>> screens;
sk_sp<SkFontMgr> fontMgr;
std::wstring savePath;

App::~App()
{
Expand Down Expand Up @@ -52,6 +54,12 @@ void App::Init(std::wstring&& cmd)
else {
createWindow();
}
pos = cmd.find(L"--dir:\"");
if (pos != std::wstring::npos) {
pos += 7; //'--dir:' 6
size_t endPos = cmd.find(L'\"', pos);
savePath = cmd.substr(pos, endPos - pos);
}
}

void App::Dispose()
Expand Down Expand Up @@ -167,7 +175,28 @@ void App::initScreens() {
}, NULL);
}

std::wstring App::createFileName() {
SYSTEMTIME localTime;
GetLocalTime(&localTime);
std::wstring name = std::format(L"{}{}{}{}{}{}{}.png", localTime.wYear, localTime.wMonth, localTime.wDay,
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds);
return name;
}

std::string App::toStdString(std::wstring&& wstr) {
int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
std::string str(count, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
return str;
}

void App::SaveFile() {
if (!savePath.empty() && std::filesystem::exists(savePath) && std::filesystem::is_directory(savePath)) {
auto filePath = std::filesystem::path{ savePath } / App::createFileName();
auto filePathStr = App::toStdString(filePath.wstring());
win->Save(filePathStr);
return;
}
IFileOpenDialog* dialog;
CLSID param1 = CLSID_FileSaveDialog, param2 = IID_IFileSaveDialog;
auto hr = CoCreateInstance(param1, NULL, CLSCTX_ALL, param2, reinterpret_cast<void**>(&dialog));
Expand All @@ -177,10 +206,7 @@ void App::SaveFile() {
return;
}
COMDLG_FILTERSPEC FileTypes[] = { { L"All Pictures", L"*.png;" },{ L"All files", L"*.*" } };
SYSTEMTIME localTime;
GetLocalTime(&localTime);
std::wstring name = std::format(L"{}{}{}{}{}{}{}", localTime.wYear, localTime.wMonth, localTime.wDay,
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds);
std::wstring name = App::createFileName();
dialog->SetFileName(name.c_str());
dialog->SetFileTypes(2, FileTypes);
dialog->SetTitle(L"Save File");
Expand Down Expand Up @@ -212,11 +238,8 @@ void App::SaveFile() {
ss << filePath;
CoTaskMemFree(filePath);
dialog->Release();
std::wstring wstr = ss.str();
int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
std::string str(count, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
win->Save(str);
auto filePathStr = App::toStdString(ss.str());
win->Save(filePathStr);
}

std::shared_ptr<SkRect> App::GetScreen(const float& x, const float& y)
Expand Down
2 changes: 2 additions & 0 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class App
static void initScreens();
static void createWindow();
static void pinClipboard();
static std::wstring createFileName();
static std::string toStdString(std::wstring&& wstr);
};

0 comments on commit c88b946

Please sign in to comment.