diff options
author | Mataes <mataes2007@gmail.com> | 2020-04-25 22:51:22 +0300 |
---|---|---|
committer | Mataes <mataes2007@gmail.com> | 2020-04-25 22:51:55 +0300 |
commit | bd690ca47f74ca04b8832b9ba736d8b7fc31773b (patch) | |
tree | ca090ac89cae0107cba1cb5affc8127f841f78bd /plugins/NewStory/src/history.cpp | |
parent | 9aad59651c77743717e36c3c9860964012258a00 (diff) |
newstory: added savefile dialog to export
Diffstat (limited to 'plugins/NewStory/src/history.cpp')
-rw-r--r-- | plugins/NewStory/src/history.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index c22b1c3eb6..013b8d2659 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -631,24 +631,44 @@ public: void onClick_Export(CCtrlButton *) { - //get folder - CMStringW tszRoot; + wchar_t FileName[MAX_PATH]; + VARSW tszMirDir(L"%miranda_userdata%\\NewStoryExport"); + MCONTACT hContact = m_hContact; if (db_mc_isMeta(m_hContact)) hContact = db_event_getContact(m_hContact); char* proto = Proto_GetBaseAccountName(hContact); ptrW id(Contact_GetInfo(CNF_UNIQUEID, hContact, proto)); - tszRoot.AppendFormat(VARSW(L"%miranda_userdata%\\NewStoryExport\\%s.json"), id); + ptrW nick(Contact_GetInfo(CNF_DISPLAY, hContact, proto)); + const char* uid = Proto_GetUniqueId(proto); + + OPENFILENAME ofn = { 0 }; + ofn.lStructSize = sizeof(ofn); + CMStringW tszFilter, tszTitle, tszFileName; + tszFilter.AppendFormat(L"%s (*.json)%c*.json%c%c", TranslateT("JSON files"), 0, 0, 0); + tszTitle.AppendFormat(TranslateT("Export %s history"), nick); + ofn.lpstrFilter = tszFilter; + ofn.hwndOwner = nullptr; + ofn.lpstrTitle = tszTitle; + ofn.lpstrFile = FileName; + ofn.nMaxFile = MAX_PATH; + ofn.nMaxFileTitle = MAX_PATH; + ofn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT; + ofn.lpstrInitialDir = tszMirDir; + *FileName = '\0'; + ofn.lpstrDefExt = L""; + if (!GetSaveFileName(&ofn)) + return; //create file - if (PathFileExistsW(tszRoot)) - DeleteFile(tszRoot); - HANDLE hFile = CreateFile(tszRoot, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (PathFileExistsW(FileName)) + DeleteFile(FileName); + HANDLE hFile = CreateFile(FileName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) { // this might be because the path isent created // so we will try to create it - if (!CreatePathToFileW(tszRoot)) - hFile = CreateFile(tszRoot, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (!CreatePathToFileW(FileName)) + hFile = CreateFile(FileName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); } //export contact info @@ -657,7 +677,7 @@ public: pInfo.push_back(JSONNode("proto", proto)); if (id != NULL) - pInfo.push_back(JSONNode("uid", T2Utf(id).get())); + pInfo.push_back(JSONNode(uid, T2Utf(id).get())); for (auto& it : pSettings) { wchar_t *szValue = db_get_wsa(hContact, proto, it); |