-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathChangeDriveDlg.cpp
145 lines (127 loc) · 4.33 KB
/
ChangeDriveDlg.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
/* 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>*/
// ChangeDrive.cpp : implementation file
//
#include "stdafx.h"
#include "IntelliFile.h"
#include "ChangeDriveDlg.h"
// CChangeDriveDlg dialog
IMPLEMENT_DYNAMIC(CChangeDriveDlg, CDialogEx)
CChangeDriveDlg::CChangeDriveDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_ChangeDriveDlg, pParent)
{
}
CChangeDriveDlg::~CChangeDriveDlg()
{
}
void CChangeDriveDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DRIVE_LIST, m_ctrlDriveList);
}
BEGIN_MESSAGE_MAP(CChangeDriveDlg, CDialogEx)
ON_LBN_DBLCLK(IDC_DRIVE_LIST, &CChangeDriveDlg::OnDblclkDriveList)
END_MESSAGE_MAP()
// CChangeDriveDlg message handlers
BOOL CChangeDriveDlg::OnInitDialog()
{
const int nVolumeNameSize = MAX_PATH + 1;
TCHAR VolumeNameBuffer[nVolumeNameSize] = { 0, };
CString strDriveName;
CDialogEx::OnInitDialog();
const DWORD nDriveList = ::GetLogicalDrives();
VERIFY(nDriveList != 0);
for (DWORD nIndex = 0; nIndex < 26; nIndex++)
{
if ((nDriveList & (1 << nIndex)) == (((DWORD)1 << nIndex)))
{
strDriveName.Format(_T("%c:\\"), (_T('A') + nIndex));
const UINT nDriveType = ::GetDriveType(strDriveName);
switch (nDriveType)
{
case DRIVE_REMOVABLE:
{
if (::GetVolumeInformation(strDriveName, VolumeNameBuffer, nVolumeNameSize, nullptr, nullptr, nullptr, nullptr, 0))
{
m_arrDriveName.Add(strDriveName);
strDriveName.Format(_T("%c: %s (%s)"), (_T('A') + nIndex), VolumeNameBuffer, _T("REMOVABLE"));
m_ctrlDriveList.AddString(strDriveName);
}
break;
}
case DRIVE_FIXED:
{
if (::GetVolumeInformation(strDriveName, VolumeNameBuffer, nVolumeNameSize, nullptr, nullptr, nullptr, nullptr, 0))
{
m_arrDriveName.Add(strDriveName);
strDriveName.Format(_T("%c: %s (%s)"), (_T('A') + nIndex), VolumeNameBuffer, _T("FIXED"));
m_ctrlDriveList.AddString(strDriveName);
}
break;
}
case DRIVE_REMOTE:
{
if (::GetVolumeInformation(strDriveName, VolumeNameBuffer, nVolumeNameSize, nullptr, nullptr, nullptr, nullptr, 0))
{
m_arrDriveName.Add(strDriveName);
strDriveName.Format(_T("%c: %s (%s)"), (_T('A') + nIndex), VolumeNameBuffer, _T("REMOTE"));
m_ctrlDriveList.AddString(strDriveName);
}
break;
}
case DRIVE_CDROM:
{
if (::GetVolumeInformation(strDriveName, VolumeNameBuffer, nVolumeNameSize, nullptr, nullptr, nullptr, nullptr, 0))
{
m_arrDriveName.Add(strDriveName);
strDriveName.Format(_T("%c: %s (%s)"), (_T('A') + nIndex), VolumeNameBuffer, _T("CDROM"));
m_ctrlDriveList.AddString(strDriveName);
}
break;
}
case DRIVE_RAMDISK:
{
if (::GetVolumeInformation(strDriveName, VolumeNameBuffer, nVolumeNameSize, nullptr, nullptr, nullptr, nullptr, 0))
{
m_arrDriveName.Add(strDriveName);
strDriveName.Format(_T("%c: %s (%s)"), (_T('A') + nIndex), VolumeNameBuffer, _T("RAMDISK"));
m_ctrlDriveList.AddString(strDriveName);
}
break;
}
default:
break; // not a drive, ERRROR!
}
}
}
m_ctrlDriveList.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChangeDriveDlg::OnOK()
{
const int nCurSel = m_ctrlDriveList.GetCurSel();
if (CB_ERR != nCurSel)
{
m_strNewDriveName = m_arrDriveName.GetAt(nCurSel);
CDialogEx::OnOK();
}
}
void CChangeDriveDlg::OnDblclkDriveList()
{
const int nCurSel = m_ctrlDriveList.GetCurSel();
if (CB_ERR != nCurSel)
{
m_strNewDriveName = m_arrDriveName.GetAt(nCurSel);
CDialogEx::OnOK();
}
}