diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-04-24 10:19:38 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-04-24 10:19:38 +0000 |
commit | 8c8b40f747b52bc5c8aa796b03ac5e7a2eb23eaf (patch) | |
tree | 6dbc4fe8a22ca14ba4d6eccfc794ed40cedd2374 | |
parent | ab90002f47192dcbb88fe5926faf52299179d815 (diff) |
Tox:
- fixed profile creation logic
- enabled "export profile" button
git-svn-id: http://svn.miranda-ng.org/main/trunk@13078 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 53 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 53 |
2 files changed, 77 insertions, 29 deletions
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 8081a6a8d1..d80e08370e 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -35,7 +35,7 @@ void CToxOptionsMain::OnInitDialog() ShowWindow(m_profileImport.GetHwnd(), FALSE);
ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE);
- //ShowWindow(m_profileExport.GetHwnd(), TRUE);
+ ShowWindow(m_profileExport.GetHwnd(), TRUE);
}
if (m_proto->IsOnline())
@@ -68,6 +68,26 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*) void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
{
+ std::tstring profilePath = m_proto->GetToxProfilePath();
+ if (!m_proto->IsFileExists(profilePath))
+ {
+ HANDLE hProfile = CreateFile(profilePath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hProfile == NULL)
+ {
+ // TODO: warh error
+ return;
+ }
+ CloseHandle(hProfile);
+
+ TOX_ERR_NEW initError;
+ m_proto->tox = tox_new(NULL, NULL, 0, &initError);
+ if (initError != TOX_ERR_NEW_OK)
+ {
+ // TODO: warh error
+ return;
+ }
+ }
+
if (m_proto->InitToxCore())
{
TCHAR *group = m_group.GetText();
@@ -88,7 +108,7 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) ShowWindow(m_profileImport.GetHwnd(), FALSE);
ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE);
- //ShowWindow(m_profileExport.GetHwnd(), TRUE);
+ ShowWindow(m_profileExport.GetHwnd(), TRUE);
}
}
@@ -116,7 +136,7 @@ void CToxOptionsMain::ProfileImport_OnClick(CCtrlButton*) }
std::tstring defaultProfilePath = m_proto->GetToxProfilePath();
- if (_tcsicmp(profilePath, defaultProfilePath.c_str()) != 0)
+ if (mir_tstrcmpi(profilePath, defaultProfilePath.c_str()) != 0)
{
CopyFile(profilePath, defaultProfilePath.c_str(), FALSE);
}
@@ -126,6 +146,33 @@ void CToxOptionsMain::ProfileImport_OnClick(CCtrlButton*) void CToxOptionsMain::ProfileExport_OnClick(CCtrlButton*)
{
+ TCHAR filter[MAX_PATH];
+ mir_sntprintf(filter, SIZEOF(filter), _T("%s(*.tox)%c*.tox%c%c"),
+ TranslateT("Tox profile"), 0, 0, 0);
+
+ TCHAR profilePath[MAX_PATH];
+ mir_tstrncpy(profilePath, _T("tox_save.tox"), SIZEOF(profilePath));
+
+ OPENFILENAME ofn = { sizeof(ofn) };
+ ofn.hwndOwner = m_hwnd;
+ ofn.lpstrFilter = filter;
+ ofn.nFilterIndex = 0;
+ ofn.lpstrFile = profilePath;
+ ofn.lpstrTitle = TranslateT("Save tox profile");\
+ ofn.nMaxFile = MAX_PATH;
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_EXPLORER;
+ ofn.lpstrInitialDir = _T("%HOMEPATH%");
+
+ if (!GetSaveFileName(&ofn))
+ {
+ return;
+ }
+
+ std::tstring defaultProfilePath = m_proto->GetToxProfilePath();
+ if (mir_tstrcmpi(profilePath, defaultProfilePath.c_str()) != 0)
+ {
+ CopyFile(defaultProfilePath.c_str(), profilePath, FALSE);
+ }
}
void CToxOptionsMain::OnApply()
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 5f13f07f4f..51361b4b34 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -22,36 +22,37 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) size_t size = 0;
uint8_t *data = NULL;
+
std::tstring profilePath = GetToxProfilePath();
- if (IsFileExists(profilePath))
+ if (!IsFileExists(profilePath))
+ return false;
+
+ FILE *profile = _tfopen(profilePath.c_str(), _T("rb"));
+ if (profile == NULL)
{
- FILE *profile = _tfopen(profilePath.c_str(), _T("rb"));
- if (profile == NULL)
- {
- debugLogA(__FUNCTION__": failed to open tox profile");
- return false;
- }
+ debugLogA(__FUNCTION__": failed to open tox profile");
+ return false;
+ }
- fseek(profile, 0, SEEK_END);
- size = ftell(profile);
- rewind(profile);
- if (size == 0)
- {
- fclose(profile);
- debugLogA(__FUNCTION__": tox profile is empty");
- return true;
- }
+ fseek(profile, 0, SEEK_END);
+ size = ftell(profile);
+ rewind(profile);
+ if (size == 0)
+ {
+ fclose(profile);
+ debugLogA(__FUNCTION__": tox profile is empty");
+ return true;
+ }
- data = (uint8_t*)mir_calloc(size);
- if (fread((char*)data, sizeof(char), size, profile) != size)
- {
- fclose(profile);
- debugLogA(__FUNCTION__": failed to read tox profile");
- mir_free(data);
- return false;
- }
+ data = (uint8_t*)mir_calloc(size);
+ if (fread((char*)data, sizeof(char), size, profile) != size)
+ {
fclose(profile);
+ debugLogA(__FUNCTION__": failed to read tox profile");
+ mir_free(data);
+ return false;
}
+ fclose(profile);
if (data != NULL && tox_is_data_encrypted(data))
{
@@ -146,8 +147,8 @@ INT_PTR CToxProto::OnCopyToxID(WPARAM, LPARAM) }
CToxPasswordEditor::CToxPasswordEditor(CToxProto *proto) :
- CToxDlgBase(proto, IDD_PASSWORD, false), ok(this, IDOK),
- password(this, IDC_PASSWORD), savePermanently(this, IDC_SAVEPERMANENTLY)
+CToxDlgBase(proto, IDD_PASSWORD, false), ok(this, IDOK),
+password(this, IDC_PASSWORD), savePermanently(this, IDC_SAVEPERMANENTLY)
{
ok.OnClick = Callback(this, &CToxPasswordEditor::OnOk);
}
|