Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / create_file_dlg.cpp
blobbc12d15625e7d19aa6ae300f7be6391d05ccd74a
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // create_file_dlg.cpp : implementation file
23 #include "std_afx.h"
24 #include "object_viewer.h"
25 #include "create_file_dlg.h"
26 #include <shlobj.h>
29 /////////////////////////////////////////////////////////////////////////////
30 // CCreateFileDlg dialog
33 CCreateFileDlg::CCreateFileDlg(const CString &title, const std::string &defaultBasePath, const std::string &extension, CWnd* pParent /*=NULL*/)
34 : CDialog(CCreateFileDlg::IDD, pParent)
36 //{{AFX_DATA_INIT(CCreateFileDlg)
37 // NOTE: the ClassWizard will add member initialization here
38 //}}AFX_DATA_INIT
39 _Title = title;
40 _Extension = extension;
41 _DefaultBasePath = defaultBasePath;
45 void CCreateFileDlg::DoDataExchange(CDataExchange* pDX)
47 CDialog::DoDataExchange(pDX);
48 //{{AFX_DATA_MAP(CCreateFileDlg)
49 // NOTE: the ClassWizard will add DDX and DDV calls here
50 //}}AFX_DATA_MAP
54 BEGIN_MESSAGE_MAP(CCreateFileDlg, CDialog)
55 //{{AFX_MSG_MAP(CCreateFileDlg)
56 ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
60 /////////////////////////////////////////////////////////////////////////////
61 // CCreateFileDlg message handlers
63 void CCreateFileDlg::OnBrowse()
65 CString chosenPath;
66 if (browseFolder(getStrRsc(IDS_CHOOSE_BASE_PATH), chosenPath, this->m_hWnd))
68 GetDlgItem(IDC_LOCATION)->SetWindowText((LPCTSTR) chosenPath);
73 //*************************************************************************************************
74 BOOL CCreateFileDlg::OnInitDialog()
76 CDialog::OnInitDialog();
77 SetWindowText((LPCTSTR) _Title);
78 GetDlgItem(IDC_LOCATION)->SetWindowText(nlUtf8ToTStr(_DefaultBasePath));
79 if (!_DefaultBasePath.empty())
81 GetDlgItem(IDC_FILENAME)->SetFocus();
83 else
85 GetDlgItem(IDC_LOCATION)->SetFocus();
87 return TRUE; // return TRUE unless you set the focus to a control
88 // EXCEPTION: OCX Property Pages should return FALSE
91 //*************************************************************************************************
92 void CCreateFileDlg::OnOK()
94 CString filename;
95 GetDlgItem(IDC_FILENAME)->GetWindowText(filename);
96 _Filename = NLMISC::tStrToUtf8(filename);
97 CString location;
98 GetDlgItem(IDC_LOCATION)->GetWindowText(location);
99 _Path = NLMISC::tStrToUtf8(location);
100 if (_Path.empty())
102 localizedMessageBox(*this, IDS_EMPTY_PATH, IDS_ERROR, MB_ICONEXCLAMATION);
103 return;
105 if (_Filename.empty())
107 localizedMessageBox(*this, IDS_FILENAME_PATH, IDS_ERROR, MB_ICONEXCLAMATION);
108 return;
110 // check that filename is valid (should be a single file name)
111 if (_Filename != NLMISC::CFile::getFilename(_Filename))
113 localizedMessageBox(*this, IDS_INVALID_FILENAME, IDS_ERROR, MB_ICONEXCLAMATION);
114 return;
116 // attempt to create containing folder
117 if (!NLMISC::CFile::isExists(_Path))
119 bool result = NLMISC::CFile::createDirectory(_Path);
120 if (!result)
122 MessageBox((LPCTSTR) (getStrRsc(IDS_COULDNT_CREATE_DIRECTORY) + _Path.c_str()), getStrRsc(IDS_ERROR), MB_ICONEXCLAMATION);
123 return;
126 std::string oldPath = NLMISC::CPath::getCurrentPath();
127 if (!NLMISC::CPath::setCurrentPath(_Path.c_str()))
129 MessageBox((LPCTSTR) (getStrRsc(IDS_COULDNT_CREATE_DIRECTORY) + _Path.c_str()), getStrRsc(IDS_ERROR), MB_ICONEXCLAMATION);
130 return;
132 _FullPath = NLMISC::CPath::getFullPath(_Filename, false);
133 NLMISC::CPath::setCurrentPath(oldPath.c_str());
134 // append extension if not present
135 if (NLMISC::nlstricmp(NLMISC::CFile::getExtension(_Filename), _Extension) != 0)
137 _Filename += "." + _Extension;
138 _FullPath += "." + _Extension;
140 CDialog::OnOK();
143 void CCreateFileDlg::OnCancel()
145 _Filename.clear();
146 _Path.clear();
147 _FullPath.clear();
148 CDialog::OnCancel();
151 //*************************************************************************************************
152 bool CCreateFileDlg::touchFile()
154 std::string path = getPath();
155 std::string filename = getFileName();
156 std::string fullPath = getFullPath();
157 // check if file already exists
158 if (NLMISC::CFile::isExists(fullPath))
160 int result = MessageBox((LPCTSTR) (CString(filename.c_str()) + getStrRsc(IDS_OVERWRITE_FILE)), getStrRsc(IDS_WARNING), MB_ICONEXCLAMATION);
161 if (result != IDOK) return false;
163 // create a dummy file
164 NLMISC::COFile testFile;
165 if (!testFile.open(fullPath))
167 localizedMessageBox(*this, IDS_CANNOT_CREATE_FILE, IDS_ERROR, MB_ICONEXCLAMATION);
168 return false;
170 testFile.close();
171 return true;