1
0
mirror of synced 2024-12-15 17:21:16 +01:00
ImHex/lib/libimhex/source/api
Tsukasa OI 08bb69c048
fix: Wrong query path when saving layouts (#1735)
### Problem description

At least on Windows (I have tested), it fails to save a layout on the
non-portable version of ImHex (unless we have an administrator
privilege).

The log (after an attempt to save a layout as "sample") will look like:

| Component | Message |
| --------- | ------- |
| `libimhex` | `Failed to save layout 'sample'. No writable path found`
|

But the underlying problem is platform-agnostic. It can be also a
problem on other platforms in other ways.

### Implementation description

The layout manager incorrectly queried whether the empty path
(effectively the current working directory) is writable before saving
the layout (not each "layouts" directories it queried earlier).

This is the snippet of the root cause.

```cxx
std::fs::path layoutPath;
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Layouts)) {
    if (!hex::fs::isPathWritable(layoutPath))
        continue;

    layoutPath = path / fileName;
}
```

Look at the argument we are passing to `isPathWritable`. `layoutPath` is
a default (empty) `std::fs::path` object and will not be updated until
the directory describing itself is confirmed to be writable.

That caused a problem on non-portable version of Windows because:

1. The current working directory is usually the one of the executable
(`imhex-gui.exe`) and
2. That directory (`C:\Program Files\ImHex` by default) is usually not
writable unless ImHex is executed with an Administrator privilege.

The argument to `isPathWritable` should be `path` (containing one of the
`layouts` directories) and this PR fixes so that.

### Screenshots

### Additional things

This issue is hard to notice when developing because, to reproduce this
bug, the current working directory MUST NOT BE writable (usually
writable when we develop, even when we are working on the non-portable
Windows builds).
2024-06-07 20:33:43 +02:00
..
achievement_manager.cpp impr: Reorder achievement save routine to never accidentally clear the file 2024-02-20 00:10:05 +01:00
content_registry.cpp feat: Added option to specify max file size to load into memory 2024-05-19 15:10:22 +02:00
event_manager.cpp refactor: Give API files more consistent names 2023-11-18 14:50:43 +01:00
imhex_api.cpp impr: Select second to last provider when last one is selected and closed 2024-06-05 23:21:15 +02:00
layout_manager.cpp fix: Wrong query path when saving layouts (#1735) 2024-06-07 20:33:43 +02:00
localization_manager.cpp impr: Various web build improvements, API cleanup (#1541) 2024-02-10 23:31:05 +01:00
plugin_manager.cpp fix: Potential crash on Linux when loading external libraries 2024-03-15 17:54:09 +01:00
project_file_manager.cpp impr: Various web build improvements, API cleanup (#1541) 2024-02-10 23:31:05 +01:00
shortcut_manager.cpp impr: Don't pass unique_ptr by const reference 2024-02-24 15:06:28 +01:00
task_manager.cpp impr: Allow providers to be closed quicker after being opened 2024-05-17 21:56:43 +02:00
theme_manager.cpp fix: Lockup when changing themes in some cases 2024-04-23 21:02:16 +02:00
tutorial_manager.cpp fix: Missing includes 2024-01-30 15:50:00 +01:00
workspace_manager.cpp fix: Workspaces not being deletable correctly in all cases 2024-05-30 16:56:39 +02:00