2
2
#include < Windows.h>
3
3
#include < shlobj.h>
4
4
#include < sstream>
5
+ #include < filesystem>
5
6
#include " include/core/SkFont.h"
6
7
#include " include/core//SkFontMgr.h"
7
8
#include " include/core/SkFontStyle.h"
@@ -24,6 +25,7 @@ WindowBase* win { nullptr };
24
25
static int exitCode{ 0 };
25
26
static std::vector<std::shared_ptr<SkRect>> screens;
26
27
sk_sp<SkFontMgr> fontMgr;
28
+ std::wstring savePath;
27
29
28
30
App::~App ()
29
31
{
@@ -52,6 +54,12 @@ void App::Init(std::wstring&& cmd)
52
54
else {
53
55
createWindow ();
54
56
}
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
+ }
55
63
}
56
64
57
65
void App::Dispose ()
@@ -167,7 +175,28 @@ void App::initScreens() {
167
175
}, NULL );
168
176
}
169
177
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
+
170
193
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
+ }
171
200
IFileOpenDialog* dialog;
172
201
CLSID param1 = CLSID_FileSaveDialog, param2 = IID_IFileSaveDialog;
173
202
auto hr = CoCreateInstance (param1, NULL , CLSCTX_ALL, param2, reinterpret_cast <void **>(&dialog));
@@ -177,10 +206,7 @@ void App::SaveFile() {
177
206
return ;
178
207
}
179
208
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 ();
184
210
dialog->SetFileName (name.c_str ());
185
211
dialog->SetFileTypes (2 , FileTypes);
186
212
dialog->SetTitle (L" Save File" );
@@ -212,11 +238,8 @@ void App::SaveFile() {
212
238
ss << filePath;
213
239
CoTaskMemFree (filePath);
214
240
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);
220
243
}
221
244
222
245
std::shared_ptr<SkRect> App::GetScreen (const float & x, const float & y)
0 commit comments