Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/fileops.c
| Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | int BLI_access(const char *filename, int mode) | ||||
| return uaccess(filename, mode); | return uaccess(filename, mode); | ||||
| } | } | ||||
| static bool delete_soft(const wchar_t *path_16, const char **error_message) | static bool delete_soft(const wchar_t *path_16, const char **error_message) | ||||
| { | { | ||||
| /* Deletes file or directory to recycling bin. The latter moves all contained files and | /* Deletes file or directory to recycling bin. The latter moves all contained files and | ||||
| * directories recursively to the recycling bin as well. */ | * directories recursively to the recycling bin as well. */ | ||||
| IFileOperation *pfo; | IFileOperation *pfo; | ||||
| IShellItem *pSI; | IShellItem *psi; | ||||
| HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); | ||||
| if (FAILED(hr)) { | if (SUCCEEDED(hr)) { | ||||
| *error_message = "Failed to initialize COM"; | /* This is also the case when COM was previously initialized and CoInitializeEx returns | ||||
| goto error_1; | * S_FALSE, which is not an error. Both HRESULT values S_OK and S_FALSE indicate success. */ | ||||
| } | |||||
| hr = CoCreateInstance( | hr = CoCreateInstance( | ||||
| &CLSID_FileOperation, NULL, CLSCTX_ALL, &IID_IFileOperation, (void **)&pfo); | &CLSID_FileOperation, NULL, CLSCTX_ALL, &IID_IFileOperation, (void **)&pfo); | ||||
| if (FAILED(hr)) { | |||||
| *error_message = "Failed to create FileOperation instance"; | |||||
| goto error_2; | |||||
| } | |||||
| if (SUCCEEDED(hr)) { | |||||
| /* Flags for deletion: | /* Flags for deletion: | ||||
| * FOF_ALLOWUNDO: Enables moving file to recycling bin. | * FOF_ALLOWUNDO: Enables moving file to recycling bin. | ||||
| * FOF_SILENT: Don't show progress dialog box. | * FOF_SILENT: Don't show progress dialog box. | ||||
| * FOF_WANTNUKEWARNING: Show dialog box if file can't be moved to recycling bin. */ | * FOF_WANTNUKEWARNING: Show dialog box if file can't be moved to recycling bin. */ | ||||
| hr = pfo->lpVtbl->SetOperationFlags(pfo, FOF_ALLOWUNDO | FOF_SILENT | FOF_WANTNUKEWARNING); | hr = pfo->lpVtbl->SetOperationFlags(pfo, FOF_ALLOWUNDO | FOF_SILENT | FOF_WANTNUKEWARNING); | ||||
| if (FAILED(hr)) { | if (SUCCEEDED(hr)) { | ||||
| *error_message = "Failed to set operation flags"; | hr = SHCreateItemFromParsingName(path_16, NULL, &IID_IShellItem, (void **)&psi); | ||||
| goto error_2; | |||||
| } | |||||
| hr = SHCreateItemFromParsingName(path_16, NULL, &IID_IShellItem, (void **)&pSI); | |||||
| if (FAILED(hr)) { | |||||
| *error_message = "Failed to parse path"; | |||||
| goto error_2; | |||||
| } | |||||
| hr = pfo->lpVtbl->DeleteItem(pfo, pSI, NULL); | if (SUCCEEDED(hr)) { | ||||
| if (FAILED(hr)) { | hr = pfo->lpVtbl->DeleteItem(pfo, psi, NULL); | ||||
| *error_message = "Failed to prepare delete operation"; | |||||
| goto error_2; | |||||
| } | |||||
| if (SUCCEEDED(hr)) { | |||||
| hr = pfo->lpVtbl->PerformOperations(pfo); | hr = pfo->lpVtbl->PerformOperations(pfo); | ||||
| if (FAILED(hr)) { | if (FAILED(hr)) { | ||||
| *error_message = "Failed to delete file or directory"; | *error_message = "Failed to prepare delete operation"; | ||||
| } | |||||
| } | |||||
| else { | |||||
| *error_message = "Failed to prepare delete operation"; | |||||
| } | |||||
| psi->lpVtbl->Release(psi); | |||||
| } | |||||
| else { | |||||
| *error_message = "Failed to parse path"; | |||||
| } | |||||
| } | |||||
| else { | |||||
| *error_message = "Failed to set operation flags"; | |||||
| } | } | ||||
| error_2: | |||||
| pfo->lpVtbl->Release(pfo); | pfo->lpVtbl->Release(pfo); | ||||
| CoUninitialize(); /* Has to be uninitialized when CoInitializeEx returns either S_OK or S_FALSE | } | ||||
| */ | else { | ||||
| error_1: | *error_message = "Failed to create FileOperation instance"; | ||||
| } | |||||
| CoUninitialize(); | |||||
| } | |||||
| else { | |||||
| *error_message = "Failed to initialize COM"; | |||||
| } | |||||
| return FAILED(hr); | return FAILED(hr); | ||||
| } | } | ||||
| static bool delete_unique(const char *path, const bool dir) | static bool delete_unique(const char *path, const bool dir) | ||||
| { | { | ||||
| bool err; | bool err; | ||||
| UTF16_ENCODE(path); | UTF16_ENCODE(path); | ||||
| ▲ Show 20 Lines • Show All 918 Lines • Show Last 20 Lines | |||||