Improve renaming files with hidden extension

We now clear the “hidden extension” flag if the user manually adds it.

We also ensure the hidden extension is not ignored by comparing base name with display name. The flag is ignored under certain circumstances.

Comparing base name with display name alone may give a false positive for localized file names.
This commit is contained in:
Allan Odgaard
2013-03-19 22:09:40 +01:00
parent 149d335335
commit 3ceefce2e4

View File

@@ -10,6 +10,7 @@
#import <OakAppKit/OakFileManager.h>
#import <OakFoundation/OakFoundation.h>
#import <OakFoundation/NSString Additions.h>
#import <ns/ns.h>
#import <io/path.h>
#import <io/move_path.h>
#import <io/resource.h>
@@ -102,8 +103,24 @@ static ino_t inode (std::string const& path)
std::string src = [[item.url path] fileSystemRepresentation];
std::string dst = path::join(path::parent(src), [[objectValue stringByReplacingOccurrencesOfString:@"/" withString:@":"] fileSystemRepresentation]);
if(path::info(src) & path::flag::hidden_extension) // FIXME files with multiple extenions have the “hidden_extension” flag ignored
dst += path::extension(src); // TODO replicate Finders heuristic for toggling “extension hidden” flag
// “hidden extension” is ignored if Finder is set to show all file extensions, if there are multiple extensions, or if no application is assigned to the extension.
std::string const baseName = path::name(src);
std::string const displayName = to_s(item.name);
bool hiddenExtension = baseName != displayName && (path::info(src) & path::flag::hidden_extension);
if(src == dst && hiddenExtension)
{
NSURL* dstURL = [NSURL fileURLWithPath:[NSString stringWithCxxString:dst]];
NSError* error;
if(![dstURL setResourceValue:@NO forKey:NSURLHasHiddenExtensionKey error:&error])
NSLog(@"%s %@", sel_getName(_cmd), error);
return;
}
if(hiddenExtension)
dst += path::extension(src);
if(src != dst)
{