Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/Controllers/Map/Helpers/OASelectedGPXHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ + (void)renameVisibleTrack:(NSString *)oldPath newPath:(NSString *)newPath
{
OAAppSettings *settings = OAAppSettings.sharedManager;
NSMutableArray *visibleGpx = [NSMutableArray arrayWithArray:settings.mapSettingVisibleGpx.get];
for (NSString *gpx in settings.mapSettingVisibleGpx.get)
for (NSString *gpx in [settings.mapSettingVisibleGpx get])
{
if ([gpx isEqualToString:oldPath])
if ([gpx compare:oldPath] == NSOrderedSame)
{
[visibleGpx removeObject:gpx];
[visibleGpx addObject:newPath];
[visibleGpx addObject:newPath.decomposedStringWithCanonicalMapping];
break;
}
}
Expand Down
13 changes: 9 additions & 4 deletions Sources/Controllers/MyPlaces/TracksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1920,29 +1920,34 @@ final class TracksViewController: UITableViewController, OATrackSavingHelperUpda
}

private func updateRenamedGpx(src: KFile, dest: KFile) {
GpxDbHelper.shared.rename(currentFile: src, newFile: dest)
guard gpxDB.renameCurrentFile(src, newFile: dest) else {
NSLog("updateRenamedGpx -> renameCurrentFile failed")
return
}

handleDeletedGpxFile(gpxFile: src)
let trackItem = TrackItem(file: dest)
trackItem.dataItem = OAGPXDatabase.sharedDb().getGPXItem(dest.path())
smartFolderHelper.addTrackItemToSmartFolder(item: trackItem)
}

private func renameFolder(newName: String, oldName: String) {
let normalizedNewName = newName.decomposedStringWithCanonicalMapping
if let smartFolder = smartFolderHelper.getSmartFolder(name: oldName) {
let oldSmartFolderId = smartFolder.getId()
smartFolderHelper.renameSmartFolder(smartFolder: smartFolder, newName: newName)
smartFolderHelper.renameSmartFolder(smartFolder: smartFolder, newName: normalizedNewName)
renameSortModeKey(from: oldSmartFolderId, to: smartFolder.getId())
updateData()
}

guard let trackFolder = getTrackFolderByPath(oldName) else { return }
let oldFolderPath = currentFolderAbsolutePath().appendingPathComponent(oldName)
let newFolderPath = currentFolderAbsolutePath().appendingPathComponent(newName)
let newFolderPath = currentFolderAbsolutePath().appendingPathComponent(normalizedNewName)

if !FileManager.default.fileExists(atPath: newFolderPath) {
let oldDir = KFile(filePath: oldFolderPath)
if let parentFile = oldDir.getParentFile() {
let newDir = KFile(file: parentFile, fileName: newName)
let newDir = KFile(file: parentFile, fileName: normalizedNewName)
if oldDir.renameTo(toFile: newDir) {
trackFolder.setDirFile(dirFile: newDir)
trackFolder.resetCachedData()
Expand Down
4 changes: 2 additions & 2 deletions Sources/GPX/OAGPXDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ typedef NS_ENUM(NSInteger, EOAGPX3DLineVisualizationPositionType) {
EOAGPX3DLineVisualizationPositionTypeTopBottom,
};

@class OASGpxTrackAnalysis;
@class OASWptPt, OASGpxDataItem;
@class OASWptPt, OASGpxDataItem, OASKFile, OASGpxTrackAnalysis;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -62,6 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
- (OASGpxDataItem *_Nullable)getGPXItem:(NSString *)filePath;

- (BOOL)updateDataItem:(OASGpxDataItem *_Nonnull)item;
- (BOOL)renameCurrentFile:(OASKFile *)currentFile newFile:(OASKFile *)newFile;
- (NSArray<OASGpxDataItem *> *)getDataItems;
- (OASGpxDataItem *)getGPXItemByFileName:(NSString *)fileName;
- (NSString *)getFileDir:(NSString *)filePath;
Expand Down
27 changes: 27 additions & 0 deletions Sources/GPX/OAGPXDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,33 @@ - (BOOL)updateDataItem:(OASGpxDataItem *)item
return [[OASGpxDbHelper shared] updateDataItemItem:item];
}

- (BOOL)renameCurrentFile:(OASKFile *)currentFile newFile:(OASKFile *)newFile
{
BOOL success = [[OASGpxDbHelper shared] renameCurrentFile:currentFile newFile:newFile];
if (!success)
return NO;

NSString *currentPath = currentFile.absolutePath;
NSString *newPath = newFile.absolutePath;
NSString *currentPathKey = currentPath.precomposedStringWithCanonicalMapping;
NSString *newPathKey = newPath.precomposedStringWithCanonicalMapping;
NSMutableArray<OASGpxDataItem *> *itemsToRemove = [NSMutableArray array];
for (OASGpxDataItem *item in [[OASGpxDbHelper shared] getItems])
{
NSString *itemPath = item.file.absolutePath;
NSString *itemPathKey = itemPath.precomposedStringWithCanonicalMapping;
BOOL isOldRenamedItem = [itemPathKey isEqualToString:currentPathKey] && ![item.file exists];
BOOL isDuplicateNewItem = [itemPathKey isEqualToString:newPathKey] && ![itemPath isEqualToString:newPath];
if (isOldRenamedItem || isDuplicateNewItem)
[itemsToRemove addObject:item];
}

for (OASGpxDataItem *item in itemsToRemove)
[[OASGpxDbHelper shared] removeItem:item];

return YES;
}

- (NSArray<OASGpxDataItem *> *)getDataItems
{
return [[OASGpxDbHelper shared] getItems];
Expand Down
1 change: 0 additions & 1 deletion Sources/Helpers/OAAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,6 @@ typedef NS_ENUM(NSInteger, EOAWikiDataSourceType)

- (void) showGpx:(NSArray<NSString *> *)filePaths;
- (void) showGpx:(NSArray<NSString *> *)filePaths update:(BOOL)update;
- (void) updateGpx:(NSArray<NSString *> *)filePaths;
- (void) hideGpx:(NSArray<NSString *> *)filePaths;
- (void) hideGpx:(NSArray<NSString *> *)filePaths update:(BOOL)update;
- (void) hideRemovedGpx;
Expand Down
58 changes: 23 additions & 35 deletions Sources/Helpers/OAAppSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -7493,9 +7493,18 @@ - (void) showGpx:(NSArray<NSString *> *)filePaths update:(BOOL)update
NSMutableArray *arr = [NSMutableArray arrayWithArray:_mapSettingVisibleGpx.get];
for (NSString *filePath in filePaths)
{
if (![arr containsObject:filePath])
BOOL containsPath = NO;
for (NSString *visiblePath in arr)
{
[arr addObject:filePath];
if ([visiblePath compare:filePath] == NSOrderedSame)
{
containsPath = YES;
break;
}
}
if (!containsPath)
{
[arr addObject:filePath.decomposedStringWithCanonicalMapping];
added = YES;
}
}
Expand All @@ -7515,35 +7524,6 @@ - (void) showGpx:(NSArray<NSString *> *)filePaths
[self showGpx:filePaths update:YES];
}

- (void) updateGpx:(NSArray<NSString *> *)filePaths
{
BOOL added = NO;
BOOL removed = NO;
NSMutableArray *arr = [NSMutableArray arrayWithArray:_mapSettingVisibleGpx.get];
for (NSString *filePath in filePaths)
{
if (![arr containsObject:filePath])
{
added = YES;
break;
}
}
for (NSString *visible in arr)
{
if (![filePaths containsObject:visible])
{
removed = YES;
break;
}
}

if (added || removed)
{
[self.mapSettingVisibleGpx set:[NSMutableArray arrayWithArray:filePaths]];
[[[OsmAndApp instance] updateGpxTracksOnMapObservable] notifyEvent];
}
}

- (void) hideGpx:(NSArray<NSString *> *)filePaths
{
[self hideGpx:filePaths update:YES];
Expand All @@ -7556,10 +7536,13 @@ - (void) hideGpx:(NSArray<NSString *> *)filePaths update:(BOOL)update
NSMutableArray *arrToDelete = [NSMutableArray array];
for (NSString *filePath in filePaths)
{
if ([arr containsObject:filePath])
for (NSString *visiblePath in arr)
{
[arrToDelete addObject:filePath];
removed = YES;
if ([visiblePath compare:filePath] == NSOrderedSame)
{
[arrToDelete addObject:visiblePath];
removed = YES;
}
}
}
[arr removeObjectsInArray:arrToDelete];
Expand All @@ -7572,7 +7555,12 @@ - (void) hideGpx:(NSArray<NSString *> *)filePaths update:(BOOL)update
- (void) hideRemovedGpx
{
OsmAndAppInstance app = [OsmAndApp instance];
NSMutableArray *arr = [NSMutableArray arrayWithArray:_mapSettingVisibleGpx.get];
NSMutableOrderedSet<NSString *> *visiblePaths = [NSMutableOrderedSet orderedSet];
for (NSString *path in _mapSettingVisibleGpx.get)
{
[visiblePaths addObject:path.decomposedStringWithCanonicalMapping];
}
NSMutableArray *arr = [NSMutableArray arrayWithArray:visiblePaths.array];
NSMutableArray *arrToDelete = [NSMutableArray array];
for (NSString *filepath in arr)
{
Expand Down
6 changes: 3 additions & 3 deletions Sources/Helpers/OAGPXUIHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ - (void)copyGPXToNewFolder:(NSString *)newFolderName
BOOL result = [trackItem.dataItem.file renameToToFile:newFile];
if (result)
{
BOOL renameCurrentFileResult = [[OASGpxDbHelper shared] renameCurrentFile:trackItem.dataItem.file newFile:newFile];
BOOL renameCurrentFileResult = [gpxDatabase renameCurrentFile:trackItem.dataItem.file newFile:newFile];
if (renameCurrentFileResult)
{
OASGpxDataItem *gpx = [[OAGPXDatabase sharedDb] getGPXItem:newStoringFullPath];
Expand Down Expand Up @@ -663,7 +663,7 @@ - (void)renameTrack:(OASGpxDataItem *)gpx
{
NSString *oldFilePath = gpx.gpxFilePath;
NSString *oldPath = [OsmAndApp.instance.gpxPath stringByAppendingPathComponent:oldFilePath];
NSString *newFileName = [newName stringByAppendingPathExtension:@"gpx"];
NSString *newFileName = [[newName stringByAppendingPathExtension:@"gpx"] decomposedStringWithCanonicalMapping];
NSString *newFilePath = [[gpx.gpxFilePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newFileName]; // 2023-10-22_11-34_Sun 2.gpx
NSString *newPath = [OsmAndApp.instance.gpxPath stringByAppendingPathComponent:newFilePath];
if (![NSFileManager.defaultManager fileExistsAtPath:newPath])
Expand All @@ -677,7 +677,7 @@ - (void)renameTrack:(OASGpxDataItem *)gpx
NSLog(@"[ERROR] -> OAGPXUIHelper -> renameToFileResult is fail");
return;
}
BOOL renameCurrentFileResult = [[OASGpxDbHelper shared] renameCurrentFile:gpx.file newFile:newFile];
BOOL renameCurrentFileResult = [[OAGPXDatabase sharedDb] renameCurrentFile:gpx.file newFile:newFile];
if (!renameCurrentFileResult)
{
NSLog(@"[ERROR] -> OAGPXUIHelper -> renameCurrentFileResult is fail");
Expand Down