Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/fileops.c
| Show First 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | 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 (FAILED(hr)) { | ||||
| *error_message = "Failed to initialize COM"; | *error_message = "Failed to initialize COM"; | ||||
LazyDodo: can't you just return here and skip the `com_initialized` variable all together? | |||||
Done Inline ActionsThe else-case is for when the COM initialization is successful and only then should COM be uninitialized later on. rjg: The else-case is for when the COM initialization is successful and only then should COM be… | |||||
Done Inline ActionsI may have misunderstood your comment. Did you mean you want an early return in the if-case? rjg: I may have misunderstood your comment. Did you mean you want an early return in the if-case? | |||||
Not Done Inline Actionsyes, i mean, if the com init call failed, unlikely any of the other stuff is going to execute? so you could bail out early in that case i think? LazyDodo: yes, i mean, if the com init call failed, unlikely any of the other stuff is going to execute? | |||||
Done Inline ActionsYes, you are right. In this particular case we could do a return in the if case and eliminate the bool. Technically you can do an early return in every step, as each one depends on the successful execution of the previous step, but then you have to duplicate code for the release and uninitialization in later parts. rjg: Yes, you are right. In this particular case we could do a return in the if case and eliminate… | |||||
| goto error_1; | goto error_1; | ||||
| } | } | ||||
| 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)) { | if (FAILED(hr)) { | ||||
| *error_message = "Failed to create FileOperation instance"; | *error_message = "Failed to create FileOperation instance"; | ||||
| goto error_2; | goto error_2; | ||||
| } | } | ||||
| /* 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 (FAILED(hr)) { | ||||
| *error_message = "Failed to set operation flags"; | *error_message = "Failed to set operation flags"; | ||||
| goto error_2; | goto error_3; | ||||
| } | } | ||||
| hr = SHCreateItemFromParsingName(path_16, NULL, &IID_IShellItem, (void **)&pSI); | hr = SHCreateItemFromParsingName(path_16, NULL, &IID_IShellItem, (void **)&pSI); | ||||
| if (FAILED(hr)) { | if (FAILED(hr)) { | ||||
| *error_message = "Failed to parse path"; | *error_message = "Failed to parse path"; | ||||
| goto error_2; | goto error_3; | ||||
| } | } | ||||
| hr = pfo->lpVtbl->DeleteItem(pfo, pSI, NULL); | hr = pfo->lpVtbl->DeleteItem(pfo, pSI, NULL); | ||||
| if (FAILED(hr)) { | if (FAILED(hr)) { | ||||
| *error_message = "Failed to prepare delete operation"; | *error_message = "Failed to prepare delete operation"; | ||||
| goto error_2; | goto error_4; | ||||
| } | } | ||||
| 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 delete file or directory"; | ||||
| } | } | ||||
| error_2: | error_4: | ||||
| pSI->lpVtbl->Release(pSI); | |||||
| error_3: | |||||
| pfo->lpVtbl->Release(pfo); | pfo->lpVtbl->Release(pfo); | ||||
| error_2: | |||||
| CoUninitialize(); /* Has to be uninitialized when CoInitializeEx returns either S_OK or S_FALSE | CoUninitialize(); /* Has to be uninitialized when CoInitializeEx returns either S_OK or S_FALSE | ||||
| */ | */ | ||||
| error_1: | error_1: | ||||
| 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) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 921 Lines • Show Last 20 Lines | |||||
can't you just return here and skip the com_initialized variable all together?