Skip to content

Commit c88b946

Browse files
committed
2.1.9
1 parent 4a25fe1 commit c88b946

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

ReadMe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ Whether there is any topic to talk about, whether it is related to this product
112112

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

115+
116+
## Stargazers over time
117+
[![Stargazers over time](https://starchart.cc/xland/ScreenCapture.svg?variant=adaptive)](https://starchart.cc/xland/ScreenCapture)

res/res.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ IDI_LOGO ICON "logo.ico"
88
IDR_ICON_FONT ICON_FONT "icon.ttf"
99

1010
VS_VERSION_INFO VERSIONINFO
11-
FILEVERSION 2,1,8,0
12-
PRODUCTVERSION 2,1,8,0
11+
FILEVERSION 2,1,9,0
12+
PRODUCTVERSION 2,1,9,0
1313
FILEFLAGSMASK 0x3fL
1414
#ifdef _DEBUG
1515
FILEFLAGS 0x1L
@@ -26,12 +26,12 @@ BEGIN
2626
BEGIN
2727
VALUE "CompanyName", "GitHub xland"
2828
VALUE "FileDescription", "ScreenCapture"
29-
VALUE "FileVersion", "2.1.8.0"
29+
VALUE "FileVersion", "2.1.9.0"
3030
VALUE "InternalName", "ScreenCapture.exe"
3131
VALUE "LegalCopyright", "Copyright (C) LiuXiaolun 2023-2024"
3232
VALUE "OriginalFilename", "ScreenCapture.exe"
3333
VALUE "ProductName", "ScreenCapture"
34-
VALUE "ProductVersion", "2.1.8.0"
34+
VALUE "ProductVersion", "2.1.9.0"
3535
END
3636
END
3737
BLOCK "VarFileInfo"

src/App.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <Windows.h>
33
#include <shlobj.h>
44
#include <sstream>
5+
#include <filesystem>
56
#include "include/core/SkFont.h"
67
#include "include/core//SkFontMgr.h"
78
#include "include/core/SkFontStyle.h"
@@ -24,6 +25,7 @@ WindowBase* win { nullptr };
2425
static int exitCode{ 0 };
2526
static std::vector<std::shared_ptr<SkRect>> screens;
2627
sk_sp<SkFontMgr> fontMgr;
28+
std::wstring savePath;
2729

2830
App::~App()
2931
{
@@ -52,6 +54,12 @@ void App::Init(std::wstring&& cmd)
5254
else {
5355
createWindow();
5456
}
57+
pos = cmd.find(L"--dir:\"");
58+
if (pos != std::wstring::npos) {
59+
pos += 7; //'--dir:' 6
60+
size_t endPos = cmd.find(L'\"', pos);
61+
savePath = cmd.substr(pos, endPos - pos);
62+
}
5563
}
5664

5765
void App::Dispose()
@@ -167,7 +175,28 @@ void App::initScreens() {
167175
}, NULL);
168176
}
169177

178+
std::wstring App::createFileName() {
179+
SYSTEMTIME localTime;
180+
GetLocalTime(&localTime);
181+
std::wstring name = std::format(L"{}{}{}{}{}{}{}.png", localTime.wYear, localTime.wMonth, localTime.wDay,
182+
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds);
183+
return name;
184+
}
185+
186+
std::string App::toStdString(std::wstring&& wstr) {
187+
int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
188+
std::string str(count, 0);
189+
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
190+
return str;
191+
}
192+
170193
void App::SaveFile() {
194+
if (!savePath.empty() && std::filesystem::exists(savePath) && std::filesystem::is_directory(savePath)) {
195+
auto filePath = std::filesystem::path{ savePath } / App::createFileName();
196+
auto filePathStr = App::toStdString(filePath.wstring());
197+
win->Save(filePathStr);
198+
return;
199+
}
171200
IFileOpenDialog* dialog;
172201
CLSID param1 = CLSID_FileSaveDialog, param2 = IID_IFileSaveDialog;
173202
auto hr = CoCreateInstance(param1, NULL, CLSCTX_ALL, param2, reinterpret_cast<void**>(&dialog));
@@ -177,10 +206,7 @@ void App::SaveFile() {
177206
return;
178207
}
179208
COMDLG_FILTERSPEC FileTypes[] = { { L"All Pictures", L"*.png;" },{ L"All files", L"*.*" } };
180-
SYSTEMTIME localTime;
181-
GetLocalTime(&localTime);
182-
std::wstring name = std::format(L"{}{}{}{}{}{}{}", localTime.wYear, localTime.wMonth, localTime.wDay,
183-
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds);
209+
std::wstring name = App::createFileName();
184210
dialog->SetFileName(name.c_str());
185211
dialog->SetFileTypes(2, FileTypes);
186212
dialog->SetTitle(L"Save File");
@@ -212,11 +238,8 @@ void App::SaveFile() {
212238
ss << filePath;
213239
CoTaskMemFree(filePath);
214240
dialog->Release();
215-
std::wstring wstr = ss.str();
216-
int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
217-
std::string str(count, 0);
218-
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL);
219-
win->Save(str);
241+
auto filePathStr = App::toStdString(ss.str());
242+
win->Save(filePathStr);
220243
}
221244

222245
std::shared_ptr<SkRect> App::GetScreen(const float& x, const float& y)

src/App.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ class App
2424
static void initScreens();
2525
static void createWindow();
2626
static void pinClipboard();
27+
static std::wstring createFileName();
28+
static std::string toStdString(std::wstring&& wstr);
2729
};

0 commit comments

Comments
 (0)