-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisk.cpp
More file actions
50 lines (44 loc) · 1.36 KB
/
Disk.cpp
File metadata and controls
50 lines (44 loc) · 1.36 KB
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
#include "pch.h"
#include "Disk.h"
#include <Windows.h>
#include <random>
CDisk::CDisk(int index, const std::wstring& name, const std::wstring& type, ULONGLONG sizeInBytes)
: m_nIndex(index), m_sName(name), m_sType(type)
{
if (sizeInBytes > 0) {
m_ullSizeInGB = sizeInBytes / 1024 / 1024 / 1024;
}
}
bool CDisk::IsRemovable() const
{
// Simple case-insensitive comparison
return _wcsicmp(m_sType.c_str(), L"Removable Media") == 0;
}
void CDisk::AssignEFIPartitionLetter()
{
std::wstring availableLetters = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::wstring usedLetters;
DWORD drives = GetLogicalDrives();
for (char i = 0; i < 26; ++i) {
if ((drives >> i) & 1) {
usedLetters += (wchar_t)(L'A' + i);
}
}
// Remove used letters from available letters
for (wchar_t used : usedLetters) {
size_t pos = availableLetters.find(used);
if (pos != std::wstring::npos) {
availableLetters.erase(pos, 1);
}
}
if (!availableLetters.empty()) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(0, availableLetters.length() - 1);
m_sEFIPartitionLetter = availableLetters[distrib(gen)];
}
else {
// Fallback or throw an exception if no letters are available
m_sEFIPartitionLetter.clear();
}
}