mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
FIX: Error if UDisks not installed.
FIX: Duplicated drives when not using UDisks.
This commit is contained in:
parent
3c64aefd7c
commit
5b16645ba3
2 changed files with 66 additions and 12 deletions
|
|
@ -522,8 +522,8 @@ var
|
|||
// so we are free to check the device name. Otherwise don't check it
|
||||
// if it is a known name=value pair.
|
||||
Result := HaveUDisksDevices or
|
||||
not StrBegins(Device, 'UUID=') or
|
||||
not StrBegins(Device, 'LABEL=');
|
||||
not (StrBegins(Device, 'UUID=') or
|
||||
StrBegins(Device, 'LABEL='));
|
||||
end;
|
||||
|
||||
// Checks if device on some mount point hasn't been added yet.
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ type
|
|||
|
||||
var
|
||||
DBusConnectionOpen: Boolean = False;
|
||||
DBusFilterInstalled: Boolean = False;
|
||||
conn: PDBusConnection;
|
||||
error: DBusError;
|
||||
Observers: TUDisksObserverList = nil;
|
||||
|
|
@ -274,6 +275,32 @@ begin
|
|||
dbus_message_unref(reply);
|
||||
end;
|
||||
|
||||
function DBusListActivatableNames(out Names: TStringArray): Boolean;
|
||||
var
|
||||
message, reply: PDBusMessage;
|
||||
replyIter: DBusMessageIter;
|
||||
begin
|
||||
message := dbus_message_new_method_call(DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS,
|
||||
'ListActivatableNames');
|
||||
if not Assigned(message) then
|
||||
begin
|
||||
Print('Cannot create message "ListActivatableNames"');
|
||||
Result := False;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := SendWithReply(message, reply, DBUS_TYPE_ARRAY, @replyIter);
|
||||
dbus_message_unref(message);
|
||||
if Result then
|
||||
begin
|
||||
Result := GetArrayOfString(@replyIter, Names);
|
||||
dbus_message_unref(reply);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function Invoke_GetProperty(const ObjectPath: UTF8String;
|
||||
const PropertyName: UTF8String;
|
||||
out reply: PDBusMessage; // reply needs to be freed by the caller.
|
||||
|
|
@ -511,12 +538,30 @@ begin
|
|||
Exit(DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
||||
end;
|
||||
|
||||
function IsUDisksActivatable: Boolean;
|
||||
var
|
||||
ServicesNames: TStringArray;
|
||||
i: Integer;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
if DBusListActivatableNames(ServicesNames) then
|
||||
begin
|
||||
for i := Low(ServicesNames) to High(ServicesNames) do
|
||||
if ServicesNames[i] = UDisksAddress then
|
||||
Exit(True);
|
||||
end
|
||||
else
|
||||
Print('Cannot list activatable services on DBUS');
|
||||
end;
|
||||
|
||||
function CheckUDisksService: Boolean;
|
||||
var
|
||||
udisks_exists: dbus_bool_t;
|
||||
start_reply: dbus_uint32_t;
|
||||
daemon_version: UTF8String;
|
||||
begin
|
||||
// Check if UDisks service is running.
|
||||
dbus_error_init(@error);
|
||||
udisks_exists := dbus_bus_name_has_owner(conn, UDisksAddress, @error);
|
||||
if CheckError('Cannot query UDisks on DBUS', @error) then
|
||||
|
|
@ -524,6 +569,10 @@ begin
|
|||
|
||||
if udisks_exists = 0 then
|
||||
begin
|
||||
// Check if UDisks service is installed and can be activated.
|
||||
if not IsUDisksActivatable then
|
||||
Exit(False);
|
||||
|
||||
dbus_error_init(@error);
|
||||
dbus_bus_start_service_by_name(conn, UDisksAddress, 0, @start_reply, @error);
|
||||
|
||||
|
|
@ -596,6 +645,7 @@ begin
|
|||
Print('Cannot add filter for DBUS connection')
|
||||
else
|
||||
begin
|
||||
DBusFilterInstalled := True;
|
||||
Dummy := TDummy.Create;
|
||||
ConnTimer := TTimer.Create(nil);
|
||||
ConnTimer.Interval := 500;
|
||||
|
|
@ -623,19 +673,23 @@ begin
|
|||
|
||||
if DBusConnectionOpen then
|
||||
begin
|
||||
dbus_error_init(@error);
|
||||
|
||||
for i := Low(UDisksMethodStr) to High(UDisksMethodStr) do
|
||||
if DBusFilterInstalled then
|
||||
begin
|
||||
dbus_bus_remove_match(
|
||||
conn,
|
||||
PChar(UDisksFilterStr + ',member=''' + UDisksMethodStr[i] + ''''),
|
||||
@error);
|
||||
for i := Low(UDisksMethodStr) to High(UDisksMethodStr) do
|
||||
begin
|
||||
dbus_error_init(@error);
|
||||
dbus_bus_remove_match(
|
||||
conn,
|
||||
PChar(UDisksFilterStr + ',member=''' + UDisksMethodStr[i] + ''''),
|
||||
@error);
|
||||
|
||||
CheckError('Cannot remove matching rule', @error);
|
||||
CheckError('Cannot remove matching rule', @error);
|
||||
end;
|
||||
|
||||
dbus_connection_remove_filter(conn, @FilterFunc, nil);
|
||||
DBusFilterInstalled := False;
|
||||
end;
|
||||
|
||||
dbus_connection_remove_filter(conn, @FilterFunc, nil);
|
||||
dbus_connection_unref(conn);
|
||||
DBusConnectionOpen := False;
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue