-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathBase64Dlg.cpp
157 lines (133 loc) · 4.74 KB
/
Base64Dlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
This file is part of IntelliFile application developed by Stefan-Mihai MOGA.
IntelliFile is an alternative Windows version to the famous Total Commander!
IntelliFile is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Open
Source Initiative, either version 3 of the License, or any later version.
IntelliFile is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
IntelliFile. If not, see <http://www.opensource.org/licenses/gpl-3.0.html>*/
// Base64Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "IntelliFile.h"
#include "Base64Dlg.h"
#include "base64.h"
// CBase64Dlg dialog
IMPLEMENT_DYNAMIC(CBase64Dlg, CDialogEx)
CBase64Dlg::CBase64Dlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_Base64Dlg, pParent)
{
}
CBase64Dlg::~CBase64Dlg()
{
}
void CBase64Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_INPUT, m_ctrlInputFile);
DDX_Control(pDX, IDC_EDIT_OUTPUT, m_ctrlOutputFile);
DDX_Control(pDX, IDC_ENCODE, m_ctrlEncode);
DDX_Control(pDX, IDC_DECODE, m_ctrlDecode);
}
BEGIN_MESSAGE_MAP(CBase64Dlg, CDialogEx)
ON_BN_CLICKED(IDC_BROWSE_INPUT, &CBase64Dlg::OnBnClickedBrowseInput)
ON_BN_CLICKED(IDC_BROWSE_OUTPUT, &CBase64Dlg::OnBnClickedBrowseOutput)
ON_BN_CLICKED(IDC_ENCODE, &CBase64Dlg::OnBnClickedEncode)
ON_BN_CLICKED(IDC_DECODE, &CBase64Dlg::OnBnClickedDecode)
END_MESSAGE_MAP()
BOOL CBase64Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_ctrlEncode.EnableWindow(FALSE);
m_ctrlDecode.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// CBase64Dlg message handlers
void CBase64Dlg::OnBnClickedBrowseInput()
{
CFileDialog pFileDialog(TRUE, NULL, NULL,
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES,
_T("All files\0*.*\0"), this);
if (pFileDialog.DoModal() == IDOK)
{
m_strInputFile = pFileDialog.GetPathName();
m_ctrlInputFile.SetWindowText(m_strInputFile);
m_ctrlEncode.EnableWindow(!m_strInputFile.IsEmpty() && !m_strOutputFile.IsEmpty());
m_ctrlDecode.EnableWindow(!m_strInputFile.IsEmpty() && !m_strOutputFile.IsEmpty());
}
}
void CBase64Dlg::OnBnClickedBrowseOutput()
{
CFileDialog pFileDialog(FALSE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_LONGNAMES | OFN_PATHMUSTEXIST,
_T("All files\0*.*\0"), this);
if (pFileDialog.DoModal() == IDOK)
{
m_strOutputFile = pFileDialog.GetPathName();
m_ctrlOutputFile.SetWindowText(m_strOutputFile);
m_ctrlEncode.EnableWindow(!m_strInputFile.IsEmpty() && !m_strOutputFile.IsEmpty());
m_ctrlDecode.EnableWindow(!m_strInputFile.IsEmpty() && !m_strOutputFile.IsEmpty());
}
}
void CBase64Dlg::OnBnClickedEncode()
{
std::ifstream pInputFile(m_strInputFile.GetBuffer(), std::ifstream::in | std::ofstream::binary);
m_strInputFile.ReleaseBuffer();
if (pInputFile.is_open())
{
std::ofstream pOutputFile(m_strOutputFile.GetBuffer(), std::ofstream::out | std::ofstream::binary);
m_strOutputFile.ReleaseBuffer();
if (pOutputFile.is_open())
{
pInputFile.seekg(0, std::ios::end);
std::streampos size = pInputFile.tellg();
char* memblock = new char[(unsigned long long)size + 1];
if (memblock)
{
pInputFile.seekg(0, std::ios::beg);
pInputFile.read(memblock, size);
memblock[size] = 0;
std::string encoded = base64_encode(reinterpret_cast<const unsigned char *>(memblock), size);
pOutputFile.write(encoded.c_str(), encoded.length());
delete[] memblock;
memblock = nullptr;
}
pOutputFile.close();
}
pInputFile.close();
}
CDialogEx::EndDialog(IDOK);
}
void CBase64Dlg::OnBnClickedDecode()
{
std::ifstream pInputFile(m_strInputFile.GetBuffer(), std::ifstream::in | std::ofstream::binary);
m_strInputFile.ReleaseBuffer();
if (pInputFile.is_open())
{
std::ofstream pOutputFile(m_strOutputFile.GetBuffer(), std::ofstream::out | std::ofstream::binary);
m_strOutputFile.ReleaseBuffer();
if (pOutputFile.is_open())
{
pInputFile.seekg(0, std::ios::end);
std::streampos size = pInputFile.tellg();
char* memblock = new char[(unsigned long long)size + 1];
if (memblock)
{
pInputFile.seekg(0, std::ios::beg);
pInputFile.read(memblock, size);
memblock[size] = 0;
std::string decoded = base64_decode(memblock);
pOutputFile.write(decoded.c_str(), decoded.length());
delete[] memblock;
memblock = nullptr;
}
pOutputFile.close();
}
pInputFile.close();
}
CDialogEx::EndDialog(IDOK);
}