/** @return A string of CPU information (model name etc.) */
string
-cpu_info ()
+cpu_info()
{
string info;
char buffer[64];
- size_t N = sizeof (buffer);
+ size_t N = sizeof(buffer);
if (sysctlbyname("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) {
info = buffer;
}
boost::filesystem::path
-directory_containing_executable ()
+directory_containing_executable()
{
return dcp::filesystem::canonical(boost::dll::program_location()).parent_path();
}
boost::filesystem::path
-resources_path ()
+resources_path()
{
return directory_containing_executable().parent_path() / "Resources";
}
boost::filesystem::path
-libdcp_resources_path ()
+libdcp_resources_path()
{
return resources_path();
}
void
run_ffprobe(boost::filesystem::path content, boost::filesystem::path out, bool err, string args)
{
- auto path = directory_containing_executable () / "ffprobe";
+ auto path = directory_containing_executable() / "ffprobe";
if (!dcp::filesystem::exists(path)) {
/* This is a hack but we need ffprobe during tests */
path = "/Users/ci/workspace/bin/ffprobe";
string const redirect = err ? "2>" : ">";
auto const ffprobe = String::compose("\"%1\" %2 \"%3\" %4 \"%5\"", path, args.empty() ? " " : args, content.string(), redirect, out.string());
- LOG_GENERAL (N_("Probing with %1"), ffprobe);
- system (ffprobe.c_str());
+ LOG_GENERAL(N_("Probing with %1"), ffprobe);
+ system(ffprobe.c_str());
}
list<pair<string, string>>
-mount_info ()
+mount_info()
{
return {};
}
boost::filesystem::path
-openssl_path ()
+openssl_path()
{
return directory_containing_executable() / "openssl";
}
#ifdef DCPOMATIC_DISK
/* Note: this isn't actually used at the moment as the disk writer is started as a service */
boost::filesystem::path
-disk_writer_path ()
+disk_writer_path()
{
return directory_containing_executable() / "dcpomatic2_disk_writer";
}
void
-Waker::nudge ()
+Waker::nudge()
{
}
-Waker::Waker ()
+Waker::Waker()
{
- boost::mutex::scoped_lock lm (_mutex);
- IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id);
+ boost::mutex::scoped_lock lm(_mutex);
+ IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR("Encoding DCP"), &_assertion_id);
}
-Waker::~Waker ()
+Waker::~Waker()
{
- boost::mutex::scoped_lock lm (_mutex);
- IOPMAssertionRelease (_assertion_id);
+ boost::mutex::scoped_lock lm(_mutex);
+ IOPMAssertionRelease(_assertion_id);
}
void
-start_tool (string executable, string app)
+start_tool(string executable, string app)
{
boost::algorithm::replace_all(app, " ", "\\ ");
exe_path /= "MacOS";
exe_path /= executable;
- pid_t pid = fork ();
+ pid_t pid = fork();
if (pid == 0) {
- LOG_GENERAL ("start_tool %1 %2 with path %3", executable, app, exe_path.string());
- int const r = system (exe_path.string().c_str());
- exit (WEXITSTATUS (r));
+ LOG_GENERAL("start_tool %1 %2 with path %3", executable, app, exe_path.string());
+ int const r = system(exe_path.string().c_str());
+ exit(WEXITSTATUS(r));
} else if (pid == -1) {
LOG_ERROR_NC("Fork failed in start_tool");
}
void
-start_batch_converter ()
+start_batch_converter()
{
start_tool("dcpomatic2_batch", variant::dcpomatic_batch_converter_app());
}
void
-start_player ()
+start_player()
{
start_tool("dcpomatic2_player", variant::dcpomatic_player_app());
}
static optional<string>
-get_vendor (CFDictionaryRef& description)
+get_vendor(CFDictionaryRef& description)
{
- void const* str = CFDictionaryGetValue (description, kDADiskDescriptionDeviceVendorKey);
+ void const* str = CFDictionaryGetValue(description, kDADiskDescriptionDeviceVendorKey);
if (!str) {
return {};
}
- auto c_str = CFStringGetCStringPtr ((CFStringRef) str, kCFStringEncodingUTF8);
+ auto c_str = CFStringGetCStringPtr((CFStringRef) str, kCFStringEncodingUTF8);
if (!c_str) {
return {};
}
- string s (c_str);
- boost::algorithm::trim (s);
+ string s(c_str);
+ boost::algorithm::trim(s);
return s;
}
static optional<string>
-get_model (CFDictionaryRef& description)
+get_model(CFDictionaryRef& description)
{
- void const* str = CFDictionaryGetValue (description, kDADiskDescriptionDeviceModelKey);
+ void const* str = CFDictionaryGetValue(description, kDADiskDescriptionDeviceModelKey);
if (!str) {
return {};
}
- auto c_str = CFStringGetCStringPtr ((CFStringRef) str, kCFStringEncodingUTF8);
+ auto c_str = CFStringGetCStringPtr((CFStringRef) str, kCFStringEncodingUTF8);
if (!c_str) {
return {};
}
- string s (c_str);
- boost::algorithm::trim (s);
+ string s(c_str);
+ boost::algorithm::trim(s);
return s;
}
bool
is_mounted(CFDictionaryRef& description)
{
- auto volume_path_key = (CFURLRef) CFDictionaryGetValue (description, kDADiskDescriptionVolumePathKey);
+ auto volume_path_key = (CFURLRef) CFDictionaryGetValue(description, kDADiskDescriptionVolumePathKey);
if (!volume_path_key) {
return false;
}
static void
-disk_appeared (DADiskRef disk, void* context)
+disk_appeared(DADiskRef disk, void* context)
{
- auto bsd_name = DADiskGetBSDName (disk);
+ auto bsd_name = DADiskGetBSDName(disk);
if (!bsd_name) {
LOG_DISK_NC("Disk with no BSDName appeared");
return;
this_disk.device = string("/dev/") + this_disk.bsd_name;
LOG_DISK("Device is %1", this_disk.device);
- CFDictionaryRef description = DADiskCopyDescription (disk);
+ CFDictionaryRef description = DADiskCopyDescription(disk);
- this_disk.vendor = get_vendor (description);
- this_disk.model = get_model (description);
+ this_disk.vendor = get_vendor(description);
+ this_disk.model = get_model(description);
LOG_DISK("Vendor/model: %1 %2", this_disk.vendor.get_value_or("[none]"), this_disk.model.get_value_or("[none]"));
this_disk.mounted = is_mounted(description);
- auto media_size_cstr = CFDictionaryGetValue (description, kDADiskDescriptionMediaSizeKey);
+ auto media_size_cstr = CFDictionaryGetValue(description, kDADiskDescriptionMediaSizeKey);
if (!media_size_cstr) {
LOG_DISK_NC("Could not read media size");
return;
this_disk.mounted ? "mounted" : "not mounted"
);
- CFNumberGetValue ((CFNumberRef) media_size_cstr, kCFNumberLongType, &this_disk.size);
- CFRelease (description);
+ CFNumberGetValue((CFNumberRef) media_size_cstr, kCFNumberLongType, &this_disk.size);
+ CFRelease(description);
reinterpret_cast<vector<OSXDisk>*>(context)->push_back(this_disk);
}
vector<Drive>
-Drive::get ()
+Drive::get()
{
using namespace boost::algorithm;
vector<OSXDisk> disks;
LOG_DISK_NC("Drive::get() has session");
- DARegisterDiskAppearedCallback (session, NULL, disk_appeared, &disks);
- auto run_loop = CFRunLoopGetCurrent ();
- DASessionScheduleWithRunLoop (session, run_loop, kCFRunLoopDefaultMode);
- CFRunLoopStop (run_loop);
+ DARegisterDiskAppearedCallback(session, NULL, disk_appeared, &disks);
+ auto run_loop = CFRunLoopGetCurrent();
+ DASessionScheduleWithRunLoop(session, run_loop, kCFRunLoopDefaultMode);
+ CFRunLoopStop(run_loop);
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, 0);
DAUnregisterCallback(session, (void *) disk_appeared, &disks);
CFRelease(session);
boost::filesystem::path
-config_path (optional<string> version)
+config_path(optional<string> version)
{
boost::filesystem::path p;
- p /= g_get_home_dir ();
+ p /= g_get_home_dir();
p /= "Library";
p /= "Preferences";
p /= "com.dcpomatic";
bool
-Drive::unmount ()
+Drive::unmount()
{
LOG_DISK_NC("Unmount operation started");
LOG_DISK("Requesting unmount of %1 from %2", _device, thread_id());
UnmountState state;
DADiskUnmount(disk, kDADiskUnmountOptionWhole, &done_callback, &state);
- CFRelease (disk);
+ CFRelease(disk);
- CFRunLoopRef run_loop = CFRunLoopGetCurrent ();
- DASessionScheduleWithRunLoop (session, run_loop, kCFRunLoopDefaultMode);
- CFRunLoopStop (run_loop);
+ CFRunLoopRef run_loop = CFRunLoopGetCurrent();
+ DASessionScheduleWithRunLoop(session, run_loop, kCFRunLoopDefaultMode);
+ CFRunLoopStop(run_loop);
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 5, 0);
CFRelease(session);
void
-disk_write_finished ()
+disk_write_finished()
{
}
void
-make_foreground_application ()
+make_foreground_application()
{
ProcessSerialNumber serial;
LIBDCP_DISABLE_WARNINGS
- GetCurrentProcess (&serial);
+ GetCurrentProcess(&serial);
LIBDCP_ENABLE_WARNINGS
- TransformProcessType (&serial, kProcessTransformToForegroundApplication);
+ TransformProcessType(&serial, kProcessTransformToForegroundApplication);
}
bool
-show_in_file_manager (boost::filesystem::path, boost::filesystem::path select)
+show_in_file_manager(boost::filesystem::path, boost::filesystem::path select)
{
- int r = system (String::compose("open -R \"%1\"", select.string()).c_str());
+ int r = system(String::compose("open -R \"%1\"", select.string()).c_str());
return static_cast<bool>(WEXITSTATUS(r));
}
/** @param s Number of seconds to sleep for */
void
-dcpomatic_sleep_seconds (int s)
+dcpomatic_sleep_seconds(int s)
{
- Sleep (s * 1000);
+ Sleep(s * 1000);
}
void
-dcpomatic_sleep_milliseconds (int ms)
+dcpomatic_sleep_milliseconds(int ms)
{
- Sleep (ms);
+ Sleep(ms);
}
/** @return A string of CPU information (model name etc.) */
string
-cpu_info ()
+cpu_info()
{
string info;
HKEY key;
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) {
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) {
return info;
}
DWORD type;
DWORD data;
- if (RegQueryValueEx (key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) {
+ if (RegQueryValueEx(key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) {
return info;
}
return info;
}
- wstring value (data / sizeof (wchar_t), L'\0');
- if (RegQueryValueEx (key, L"ProcessorNameString", 0, 0, reinterpret_cast<LPBYTE> (&value[0]), &data) != ERROR_SUCCESS) {
- RegCloseKey (key);
+ wstring value(data / sizeof(wchar_t), L'\0');
+ if (RegQueryValueEx(key, L"ProcessorNameString", 0, 0, reinterpret_cast<LPBYTE>(&value[0]), &data) != ERROR_SUCCESS) {
+ RegCloseKey(key);
return info;
}
- info = string (value.begin(), value.end());
+ info = string(value.begin(), value.end());
- RegCloseKey (key);
+ RegCloseKey(key);
return info;
}
run_ffprobe(boost::filesystem::path content, boost::filesystem::path out, bool err, string args)
{
SECURITY_ATTRIBUTES security;
- security.nLength = sizeof (security);
+ security.nLength = sizeof(security);
security.bInheritHandle = TRUE;
security.lpSecurityDescriptor = 0;
HANDLE child_out_read;
HANDLE child_out_write;
if (!CreatePipe(&child_out_read, &child_out_write, &security, 0)) {
- LOG_ERROR_NC ("ffprobe call failed (could not CreatePipe)");
+ LOG_ERROR_NC("ffprobe call failed (could not CreatePipe)");
return;
}
}
wchar_t dir[512];
- MultiByteToWideChar (CP_UTF8, 0, directory_containing_executable().string().c_str(), -1, dir, sizeof(dir));
+ MultiByteToWideChar(CP_UTF8, 0, directory_containing_executable().string().c_str(), -1, dir, sizeof(dir));
STARTUPINFO startup_info;
- ZeroMemory (&startup_info, sizeof (startup_info));
- startup_info.cb = sizeof (startup_info);
+ ZeroMemory(&startup_info, sizeof(startup_info));
+ startup_info.cb = sizeof(startup_info);
if (err) {
startup_info.hStdError = child_out_write;
} else {
wcscat(command, L"\"");
PROCESS_INFORMATION process_info;
- ZeroMemory (&process_info, sizeof (process_info));
- if (!CreateProcess (0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, dir, &startup_info, &process_info)) {
- LOG_ERROR_NC (N_("ffprobe call failed (could not CreateProcess)"));
+ ZeroMemory(&process_info, sizeof(process_info));
+ if (!CreateProcess(0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, dir, &startup_info, &process_info)) {
+ LOG_ERROR_NC(N_("ffprobe call failed (could not CreateProcess)"));
return;
}
dcp::File o(out, "w");
if (!o) {
- LOG_ERROR_NC (N_("ffprobe call failed (could not create output file)"));
+ LOG_ERROR_NC(N_("ffprobe call failed (could not create output file)"));
return;
}
o.close();
- WaitForSingleObject (process_info.hProcess, INFINITE);
- CloseHandle (process_info.hProcess);
- CloseHandle (process_info.hThread);
+ WaitForSingleObject(process_info.hProcess, INFINITE);
+ CloseHandle(process_info.hProcess);
+ CloseHandle(process_info.hThread);
CloseHandle(child_out_read);
}
list<pair<string, string>>
-mount_info ()
+mount_info()
{
return {};
}
boost::filesystem::path
-directory_containing_executable ()
+directory_containing_executable()
{
return boost::dll::program_location().parent_path();
}
boost::filesystem::path
-resources_path ()
+resources_path()
{
return directory_containing_executable().parent_path();
}
boost::filesystem::path
-libdcp_resources_path ()
+libdcp_resources_path()
{
- return resources_path ();
+ return resources_path();
}
boost::filesystem::path
-openssl_path ()
+openssl_path()
{
return directory_containing_executable() / "openssl.exe";
}
#ifdef DCPOMATIC_DISK
boost::filesystem::path
-disk_writer_path ()
+disk_writer_path()
{
return directory_containing_executable() / "dcpomatic2_disk_writer.exe";
}
void
-Waker::nudge ()
+Waker::nudge()
{
- boost::mutex::scoped_lock lm (_mutex);
- SetThreadExecutionState (ES_SYSTEM_REQUIRED);
+ boost::mutex::scoped_lock lm(_mutex);
+ SetThreadExecutionState(ES_SYSTEM_REQUIRED);
}
-Waker::Waker ()
+Waker::Waker()
{
}
-Waker::~Waker ()
+Waker::~Waker()
{
}
void
-start_tool (string executable)
+start_tool(string executable)
{
auto batch = directory_containing_executable() / executable;
STARTUPINFO startup_info;
- ZeroMemory (&startup_info, sizeof (startup_info));
- startup_info.cb = sizeof (startup_info);
+ ZeroMemory(&startup_info, sizeof(startup_info));
+ startup_info.cb = sizeof(startup_info);
PROCESS_INFORMATION process_info;
- ZeroMemory (&process_info, sizeof (process_info));
+ ZeroMemory(&process_info, sizeof(process_info));
wchar_t cmd[512];
- MultiByteToWideChar (CP_UTF8, 0, batch.string().c_str(), -1, cmd, sizeof(cmd));
- CreateProcess (0, cmd, 0, 0, FALSE, 0, 0, 0, &startup_info, &process_info);
+ MultiByteToWideChar(CP_UTF8, 0, batch.string().c_str(), -1, cmd, sizeof(cmd));
+ CreateProcess(0, cmd, 0, 0, FALSE, 0, 0, 0, &startup_info, &process_info);
}
void
-start_batch_converter ()
+start_batch_converter()
{
- start_tool ("dcpomatic2_batch");
+ start_tool("dcpomatic2_batch");
}
void
-start_player ()
+start_player()
{
- start_tool ("dcpomatic2_player");
+ start_tool("dcpomatic2_player");
}
uint64_t
-thread_id ()
+thread_id()
{
- return (uint64_t) GetCurrentThreadId ();
+ return (uint64_t) GetCurrentThreadId();
}
static string
-wchar_to_utf8 (wchar_t const * s)
+wchar_to_utf8(wchar_t const * s)
{
int const length = (wcslen(s) + 1) * 2;
std::vector<char> utf8(length);
- WideCharToMultiByte (CP_UTF8, 0, s, -1, utf8.data(), length, 0, 0);
- string u (utf8.data());
+ WideCharToMultiByte(CP_UTF8, 0, s, -1, utf8.data(), length, 0, 0);
+ string u(utf8.data());
return u;
}
int
-avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags)
+avio_open_boost(AVIOContext** s, boost::filesystem::path file, int flags)
{
- return avio_open (s, wchar_to_utf8(file.c_str()).c_str(), flags);
+ return avio_open(s, wchar_to_utf8(file.c_str()).c_str(), flags);
}
void
-maybe_open_console ()
+maybe_open_console()
{
- if (Config::instance()->win32_console ()) {
+ if (Config::instance()->win32_console()) {
AllocConsole();
auto handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
boost::filesystem::path
-home_directory ()
+home_directory()
{
PWSTR wide_path;
auto result = SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &wide_path);
/** @return true if this process is a 32-bit one running on a 64-bit-capable OS */
bool
-running_32_on_64 ()
+running_32_on_64()
{
BOOL p;
- IsWow64Process (GetCurrentProcess(), &p);
+ IsWow64Process(GetCurrentProcess(), &p);
return p;
}
static optional<string>
-get_friendly_name (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
+get_friendly_name(HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
{
wchar_t buffer[MAX_PATH];
- ZeroMemory (&buffer, sizeof(buffer));
- bool r = SetupDiGetDeviceRegistryPropertyW (
+ ZeroMemory(&buffer, sizeof(buffer));
+ bool r = SetupDiGetDeviceRegistryPropertyW(
device_info, device_info_data, SPDRP_FRIENDLYNAME, 0, reinterpret_cast<PBYTE>(buffer), sizeof(buffer), 0
);
if (!r) {
return optional<string>();
}
- return wchar_to_utf8 (buffer);
+ return wchar_to_utf8(buffer);
}
static optional<int>
-get_device_number (HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
+get_device_number(HDEVINFO device_info, SP_DEVINFO_DATA* device_info_data)
{
/* Find the Windows path to the device */
SP_DEVICE_INTERFACE_DATA device_interface_data;
device_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
- auto r = SetupDiEnumDeviceInterfaces (device_info, device_info_data, &GUID_DEVICE_INTERFACE_DISK, 0, &device_interface_data);
+ auto r = SetupDiEnumDeviceInterfaces(device_info, device_info_data, &GUID_DEVICE_INTERFACE_DISK, 0, &device_interface_data);
if (!r) {
LOG_DISK("SetupDiEnumDeviceInterfaces failed (%1)", GetLastError());
return optional<int>();
/* Find out how much space we need for our SP_DEVICE_INTERFACE_DETAIL_DATA_W */
DWORD size;
r = SetupDiGetDeviceInterfaceDetailW(device_info, &device_interface_data, 0, 0, &size, 0);
- PSP_DEVICE_INTERFACE_DETAIL_DATA_W device_detail_data = static_cast<PSP_DEVICE_INTERFACE_DETAIL_DATA_W> (malloc(size));
+ PSP_DEVICE_INTERFACE_DETAIL_DATA_W device_detail_data = static_cast<PSP_DEVICE_INTERFACE_DETAIL_DATA_W>(malloc(size));
if (!device_detail_data) {
LOG_DISK_NC("malloc failed");
return optional<int>();
device_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
/* And get the path */
- r = SetupDiGetDeviceInterfaceDetailW (device_info, &device_interface_data, device_detail_data, size, &size, 0);
+ r = SetupDiGetDeviceInterfaceDetailW(device_info, &device_interface_data, device_detail_data, size, &size, 0);
if (!r) {
LOG_DISK_NC("SetupDiGetDeviceInterfaceDetailW failed");
- free (device_detail_data);
+ free(device_detail_data);
return optional<int>();
}
/* Open it. We would not be allowed GENERIC_READ access here but specifying 0 for
dwDesiredAccess allows us to query some metadata.
*/
- auto device = CreateFileW (
+ auto device = CreateFileW(
device_detail_data->DevicePath, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0
);
- free (device_detail_data);
+ free(device_detail_data);
if (device == INVALID_HANDLE_VALUE) {
LOG_DISK("CreateFileW failed with %1", GetLastError());
/* Get the device number */
STORAGE_DEVICE_NUMBER device_number;
- r = DeviceIoControl (
+ r = DeviceIoControl(
device, IOCTL_STORAGE_GET_DEVICE_NUMBER, 0, 0,
&device_number, sizeof(device_number), &size, 0
);
- CloseHandle (device);
+ CloseHandle(device);
if (!r) {
return {};
* to @ref disks.
*/
static void
-add_volume_mount_points (wchar_t* volume, MountPoints& mount_points)
+add_volume_mount_points(wchar_t* volume, MountPoints& mount_points)
{
LOG_DISK("Looking at %1", wchar_to_utf8(volume));
if (GetVolumePathNamesForVolumeNameW(volume, volume_path_names, sizeof(volume_path_names) / sizeof(wchar_t), &returned)) {
wchar_t* p = volume_path_names;
while (*p != L'\0') {
- mp.push_back (wchar_to_utf8(p));
- LOG_DISK ("Found mount point %1", wchar_to_utf8(p));
+ mp.push_back(wchar_to_utf8(p));
+ LOG_DISK("Found mount point %1", wchar_to_utf8(p));
p += wcslen(p) + 1;
}
}
/* Strip trailing \ */
- size_t const len = wcslen (volume);
- DCPOMATIC_ASSERT (len > 0);
+ size_t const len = wcslen(volume);
+ DCPOMATIC_ASSERT(len > 0);
volume[len - 1] = L'\0';
- auto handle = CreateFileW (
+ auto handle = CreateFileW(
volume, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0
);
- DCPOMATIC_ASSERT (handle != INVALID_HANDLE_VALUE);
+ DCPOMATIC_ASSERT(handle != INVALID_HANDLE_VALUE);
VOLUME_DISK_EXTENTS extents;
DWORD size;
- BOOL r = DeviceIoControl (handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, 0, 0, &extents, sizeof(extents), &size, 0);
- CloseHandle (handle);
+ BOOL r = DeviceIoControl(handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, 0, 0, &extents, sizeof(extents), &size, 0);
+ CloseHandle(handle);
if (!r) {
return;
}
- DCPOMATIC_ASSERT (extents.NumberOfDiskExtents == 1);
+ DCPOMATIC_ASSERT(extents.NumberOfDiskExtents == 1);
mount_points[extents.Extents[0].DiskNumber] = mp;
}
MountPoints
-find_mount_points ()
+find_mount_points()
{
MountPoints mount_points;
wchar_t volume_name[512];
- auto volume = FindFirstVolumeW (volume_name, sizeof(volume_name) / sizeof(wchar_t));
+ auto volume = FindFirstVolumeW(volume_name, sizeof(volume_name) / sizeof(wchar_t));
if (volume == INVALID_HANDLE_VALUE) {
return MountPoints();
}
- add_volume_mount_points (volume_name, mount_points);
+ add_volume_mount_points(volume_name, mount_points);
while (true) {
if (!FindNextVolumeW(volume, volume_name, sizeof(volume_name) / sizeof(wchar_t))) {
break;
}
- add_volume_mount_points (volume_name, mount_points);
+ add_volume_mount_points(volume_name, mount_points);
}
- FindVolumeClose (volume);
+ FindVolumeClose(volume);
return mount_points;
}
vector<Drive>
-Drive::get ()
+Drive::get()
{
vector<Drive> drives;
- auto mount_points = find_mount_points ();
+ auto mount_points = find_mount_points();
/* Get a `device information set' containing information about all disks */
- auto device_info = SetupDiGetClassDevsA (&GUID_DEVICE_INTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
+ auto device_info = SetupDiGetClassDevsA(&GUID_DEVICE_INTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (device_info == INVALID_HANDLE_VALUE) {
- LOG_DISK_NC ("SetupDiClassDevsA failed");
+ LOG_DISK_NC("SetupDiClassDevsA failed");
return drives;
}
if (!SetupDiEnumDeviceInfo(device_info, i, &device_info_data)) {
DWORD e = GetLastError();
if (e != ERROR_NO_MORE_ITEMS) {
- LOG_DISK ("SetupDiEnumDeviceInfo failed (%1)", GetLastError());
+ LOG_DISK("SetupDiEnumDeviceInfo failed (%1)", GetLastError());
}
break;
}
++i;
- auto const friendly_name = get_friendly_name (device_info, &device_info_data);
- auto device_number = get_device_number (device_info, &device_info_data);
+ auto const friendly_name = get_friendly_name(device_info, &device_info_data);
+ auto device_number = get_device_number(device_info, &device_info_data);
if (!device_number) {
continue;
}
string const physical_drive = String::compose("\\\\.\\PHYSICALDRIVE%1", *device_number);
- HANDLE device = CreateFileA (
+ HANDLE device = CreateFileA(
physical_drive.c_str(), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0
DISK_GEOMETRY geom;
DWORD returned;
- BOOL r = DeviceIoControl (
+ BOOL r = DeviceIoControl(
device, IOCTL_DISK_GET_DRIVE_GEOMETRY, 0, 0,
&geom, sizeof(geom), &returned, 0
);
if (r) {
uint64_t const disk_size = geom.Cylinders.QuadPart * geom.TracksPerCylinder * geom.SectorsPerTrack * geom.BytesPerSector;
- drives.push_back (Drive(physical_drive, locked ? vector<boost::filesystem::path>() : mount_points[*device_number], disk_size, friendly_name, optional<string>()));
+ drives.push_back(Drive(physical_drive, locked ? vector<boost::filesystem::path>() : mount_points[*device_number], disk_size, friendly_name, optional<string>()));
LOG_DISK("Added drive %1%2", drives.back().log_summary(), locked ? "(locked by us)" : "");
}
- CloseHandle (device);
+ CloseHandle(device);
}
return drives;
bool
-Drive::unmount ()
+Drive::unmount()
{
LOG_DISK("Unmounting %1 with %2 mount points", _device, _mount_points.size());
- DCPOMATIC_ASSERT (_mount_points.size() == 1);
- string const device_name = String::compose ("\\\\.\\%1", _mount_points.front());
- string const truncated = device_name.substr (0, device_name.length() - 1);
+ DCPOMATIC_ASSERT(_mount_points.size() == 1);
+ string const device_name = String::compose("\\\\.\\%1", _mount_points.front());
+ string const truncated = device_name.substr(0, device_name.length() - 1);
LOG_DISK("Actually opening %1", truncated);
- HANDLE device = CreateFileA (truncated.c_str(), (GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
+ HANDLE device = CreateFileA(truncated.c_str(), (GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
if (device == INVALID_HANDLE_VALUE) {
LOG_DISK("Could not open %1 for unmount (%2)", truncated, GetLastError());
return false;
}
DWORD returned;
- BOOL r = DeviceIoControl (device, FSCTL_LOCK_VOLUME, 0, 0, 0, 0, &returned, 0);
+ BOOL r = DeviceIoControl(device, FSCTL_LOCK_VOLUME, 0, 0, 0, 0, &returned, 0);
if (!r) {
LOG_DISK("Unmount of %1 failed (%2)", truncated, GetLastError());
return false;
}
LOG_DISK("Unmount of %1 succeeded", _device);
- locked_volumes.push_back (make_pair(device, _device));
+ locked_volumes.push_back(make_pair(device, _device));
return true;
}
boost::filesystem::path
-config_path (optional<string> version)
+config_path(optional<string> version)
{
boost::filesystem::path p;
- p /= g_get_user_config_dir ();
+ p /= g_get_user_config_dir();
p /= "dcpomatic2";
if (version) {
p /= *version;
void
-disk_write_finished ()
+disk_write_finished()
{
for (auto const& i: locked_volumes) {
- CloseHandle (i.first);
+ CloseHandle(i.first);
}
}
string
-dcpomatic::get_process_id ()
+dcpomatic::get_process_id()
{
return fmt::to_string(GetCurrentProcessId());
}
bool
-show_in_file_manager (boost::filesystem::path, boost::filesystem::path select)
+show_in_file_manager(boost::filesystem::path, boost::filesystem::path select)
{
std::wstringstream args;
args << "/select," << select;
- auto const r = ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
+ auto const r = ShellExecute(0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
return (reinterpret_cast<int64_t>(r) <= 32);
}