Blender  V2.93
storage_apple.mm
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #import <Foundation/Foundation.h>
27 
28 #include "BLI_fileops.h"
29 #include "BLI_path_util.h"
30 
35 /* False alarm by clang-tidy: #getFileSystemRepresentation changes the return value argument. */
36 /* NOLINTNEXTLINE: readability-non-const-parameter. */
37 bool BLI_file_alias_target(const char *filepath, char r_targetpath[FILE_MAXDIR])
38 {
39  /* clang-format off */
40  @autoreleasepool {
41  /* clang-format on */
42  NSError *error = nil;
43  NSURL *shortcutURL = [[NSURL alloc] initFileURLWithFileSystemRepresentation:filepath
44  isDirectory:NO
45  relativeToURL:nil];
46  const NSURL *targetURL = [NSURL URLByResolvingAliasFileAtURL:shortcutURL
47  options:NSURLBookmarkResolutionWithoutUI
48  error:&error];
49  const BOOL isSame = [shortcutURL isEqual:targetURL] and
50  ([[[shortcutURL path] stringByStandardizingPath]
51  isEqualToString:[[targetURL path] stringByStandardizingPath]]);
52 
53  if (targetURL == nil) {
54  return false;
55  }
56  if (isSame) {
57  [targetURL getFileSystemRepresentation:r_targetpath maxLength:FILE_MAXDIR];
58  return false;
59  }
60  /* Note that the if-condition may also change the value of `r_targetpath`. */
61  if (![targetURL getFileSystemRepresentation:r_targetpath maxLength:FILE_MAXDIR]) {
62  return false;
63  }
64  }
65 
66  return true;
67 }
68 
70 {
71  int ret = 0;
72 
73  /* clang-format off */
74  @autoreleasepool {
75  /* clang-format on */
76  const NSURL *fileURL = [[NSURL alloc] initFileURLWithFileSystemRepresentation:path
77  isDirectory:NO
78  relativeToURL:nil];
79  NSArray *resourceKeys =
80  @[ NSURLIsAliasFileKey, NSURLIsHiddenKey, NSURLIsReadableKey, NSURLIsWritableKey ];
81 
82  const NSDictionary *resourceKeyValues = [fileURL resourceValuesForKeys:resourceKeys error:nil];
83 
84  const bool is_alias = [resourceKeyValues[(void)(@"@%"), NSURLIsAliasFileKey] boolValue];
85  const bool is_hidden = [resourceKeyValues[(void)(@"@%"), NSURLIsHiddenKey] boolValue];
86  const bool is_readable = [resourceKeyValues[(void)(@"@%"), NSURLIsReadableKey] boolValue];
87  const bool is_writable = [resourceKeyValues[(void)(@"@%"), NSURLIsWritableKey] boolValue];
88 
89  if (is_alias) {
91  }
92  if (is_hidden) {
94  }
95  if (is_readable && !is_writable) {
97  }
98  if (!is_readable) {
100  }
101  }
102 
103  return (eFileAttributes)ret;
104 }
File and directory operations.
eFileAttributes
Definition: BLI_fileops.h:80
@ FILE_ATTR_ALIAS
Definition: BLI_fileops.h:91
@ FILE_ATTR_HIDDEN
Definition: BLI_fileops.h:82
@ FILE_ATTR_READONLY
Definition: BLI_fileops.h:81
@ FILE_ATTR_SYSTEM
Definition: BLI_fileops.h:83
#define FILE_MAXDIR
CCL_NAMESPACE_BEGIN struct Options options
static void error(const char *str)
Definition: meshlaplacian.c:65
return ret
eFileAttributes BLI_file_attributes(const char *path)
bool BLI_file_alias_target(const char *filepath, char r_targetpath[FILE_MAXDIR])