macOS: move deleted file to Trash
As opposed to permanently deleting it. As requested: https://sourceforge.net/p/tuxpaint/feature-requests/148/
This commit is contained in:
parent
59ef64b4e5
commit
98198591b5
5 changed files with 30 additions and 7 deletions
|
|
@ -29,6 +29,7 @@ const char *apple_fontsPath(void);
|
||||||
const char *apple_preferencesPath(void);
|
const char *apple_preferencesPath(void);
|
||||||
const char *apple_globalPreferencesPath(void);
|
const char *apple_globalPreferencesPath(void);
|
||||||
const char *apple_picturesPath(void);
|
const char *apple_picturesPath(void);
|
||||||
|
int apple_trash(const char *path);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __IOS_H__ */
|
#endif /* __IOS_H__ */
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
@ -86,3 +87,9 @@ const char *apple_picturesPath(void)
|
||||||
{
|
{
|
||||||
return IOS_PICTURES_PATH;
|
return IOS_PICTURES_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int apple_trash(const char *path)
|
||||||
|
{
|
||||||
|
return unlink(path);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ const char *apple_fontsPath(void);
|
||||||
const char *apple_preferencesPath(void);
|
const char *apple_preferencesPath(void);
|
||||||
const char *apple_globalPreferencesPath(void);
|
const char *apple_globalPreferencesPath(void);
|
||||||
const char *apple_picturesPath(void);
|
const char *apple_picturesPath(void);
|
||||||
|
int apple_trash(const char *path);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __MACOS_H__ */
|
#endif /* __MACOS_H__ */
|
||||||
|
|
|
||||||
16
src/macos.m
16
src/macos.m
|
|
@ -221,3 +221,19 @@ const char *apple_picturesPath(void)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int apple_trash(const char *path)
|
||||||
|
{
|
||||||
|
NSFileManager *manager = [NSFileManager defaultManager];
|
||||||
|
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]];
|
||||||
|
NSURL *trash = nil;
|
||||||
|
NSError *error = nil;
|
||||||
|
|
||||||
|
[manager trashItemAtURL:url resultingItemURL:&trash error:&error];
|
||||||
|
if(error) {
|
||||||
|
DEBUG_PRINTF("%s\n", [[error localizedDescription] UTF8String]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -28056,11 +28056,12 @@ int main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
static int trash(char *path)
|
static int trash(char *path)
|
||||||
{
|
{
|
||||||
#ifdef UNLINK_ONLY
|
#if defined(UNLINK_ONLY)
|
||||||
return (unlink(path));
|
return (unlink(path));
|
||||||
#else
|
#elif defined(WIN32)
|
||||||
#ifdef WIN32
|
|
||||||
return win32_trash(path);
|
return win32_trash(path);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
return apple_trash(path);
|
||||||
#else
|
#else
|
||||||
char fname[MAX_PATH], trashpath[MAX_PATH], dest[MAX_PATH], infoname[MAX_PATH], bname[MAX_PATH], ext[MAX_PATH];
|
char fname[MAX_PATH], trashpath[MAX_PATH], dest[MAX_PATH], infoname[MAX_PATH], bname[MAX_PATH], ext[MAX_PATH];
|
||||||
char deldate[32];
|
char deldate[32];
|
||||||
|
|
@ -28220,13 +28221,10 @@ static int trash(char *path)
|
||||||
|
|
||||||
/* FIXME: xcfe and elsewhere: Anything to do? */
|
/* FIXME: xcfe and elsewhere: Anything to do? */
|
||||||
|
|
||||||
/* FIXME: Mac OS X */
|
|
||||||
|
|
||||||
/* FIXME: Haiku */
|
/* FIXME: Haiku */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
#endif /* WIN32 */
|
#endif
|
||||||
#endif /* UNLINK_ONLY */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue