Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix palette cloud sync #4061

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions OsmAnd.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
462545AB28D3688900637964 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 462545A728D3688800637964 /* [email protected] */; };
4625AF902C2335870099EB89 /* TerrainMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4625AF8F2C2335870099EB89 /* TerrainMode.swift */; };
4627664D283D766E00F412F6 /* OASubscriptionCardView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4627664C283D766E00F412F6 /* OASubscriptionCardView.xib */; };
462B6C782CB6C2C900DD6C7E /* BackupUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 462B6C772CB6C2C900DD6C7E /* BackupUtils.swift */; };
462BF6DC2B7E8347003ECA2C /* DeleteAccountCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 462BF6DB2B7E8347003ECA2C /* DeleteAccountCommand.swift */; };
462E13E82BFA36D40038BCCB /* CustomMapButtonsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 462E13E72BFA36D40038BCCB /* CustomMapButtonsViewController.swift */; };
462F13EB283FD0D400B73795 /* OAOsmLiveFeaturesCardView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 462F13E9283FD0D300B73795 /* OAOsmLiveFeaturesCardView.xib */; };
Expand Down Expand Up @@ -784,6 +785,7 @@
46DB0A632C5CEA8F001356D5 /* ConcurrentArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46DB0A622C5CEA8F001356D5 /* ConcurrentArray.swift */; };
46DB0A7E2C5D1602001356D5 /* GradientUiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46DB0A7D2C5D1602001356D5 /* GradientUiHelper.swift */; };
46DC808629B8898700C477C3 /* OADownloadMode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46DC808529B8889200C477C3 /* OADownloadMode.mm */; };
46DD3CCD2CBD560F0087F8F0 /* LocalFileHashHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46DD3CCC2CBD560F0087F8F0 /* LocalFileHashHelper.swift */; };
46DF1D7F28C21B4300135D94 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 46DF1D7B28C21B4100135D94 /* [email protected] */; };
46DF1D8028C21B4300135D94 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 46DF1D7C28C21B4200135D94 /* [email protected] */; };
46DF1D8128C21B4300135D94 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 46DF1D7D28C21B4200135D94 /* [email protected] */; };
Expand Down Expand Up @@ -3922,6 +3924,7 @@
462545A728D3688800637964 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Icons/[email protected]"; sourceTree = "<group>"; };
4625AF8F2C2335870099EB89 /* TerrainMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerrainMode.swift; sourceTree = "<group>"; };
4627664C283D766E00F412F6 /* OASubscriptionCardView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = OASubscriptionCardView.xib; sourceTree = "<group>"; };
462B6C772CB6C2C900DD6C7E /* BackupUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupUtils.swift; sourceTree = "<group>"; };
462BF6DB2B7E8347003ECA2C /* DeleteAccountCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountCommand.swift; sourceTree = "<group>"; };
462E13E72BFA36D40038BCCB /* CustomMapButtonsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomMapButtonsViewController.swift; sourceTree = "<group>"; };
462F13E9283FD0D300B73795 /* OAOsmLiveFeaturesCardView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OAOsmLiveFeaturesCardView.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4192,6 +4195,7 @@
46DB0A7D2C5D1602001356D5 /* GradientUiHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientUiHelper.swift; sourceTree = "<group>"; };
46DC808429B8887600C477C3 /* OADownloadMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OADownloadMode.h; sourceTree = "<group>"; };
46DC808529B8889200C477C3 /* OADownloadMode.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = OADownloadMode.mm; sourceTree = "<group>"; };
46DD3CCC2CBD560F0087F8F0 /* LocalFileHashHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalFileHashHelper.swift; sourceTree = "<group>"; };
46DF1D7B28C21B4100135D94 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Icons/[email protected]"; sourceTree = "<group>"; };
46DF1D7C28C21B4200135D94 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Icons/[email protected]"; sourceTree = "<group>"; };
46DF1D7D28C21B4200135D94 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/Icons/[email protected]"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -13460,6 +13464,7 @@
DAA9F44B27EC9E99002BB1A8 /* Commands */,
DA4ABED22876D98D00B996EF /* LocalBackup */,
4657490F2B68129B0006046B /* BackupUiUtils.swift */,
462B6C772CB6C2C900DD6C7E /* BackupUtils.swift */,
DA1A886227FC66DA00A82DF6 /* OABackupDbHelper.h */,
DA1A886327FC66DA00A82DF6 /* OABackupDbHelper.m */,
DAA9F44F27ECA5F6002BB1A8 /* OABackupError.h */,
Expand Down Expand Up @@ -13502,6 +13507,7 @@
DA9901B22918F14700A3C732 /* OASyncBackupTask.mm */,
465749112B681E620006046B /* TrashGroup.swift */,
4657490D2B6803710006046B /* TrashItem.swift */,
46DD3CCC2CBD560F0087F8F0 /* LocalFileHashHelper.swift */,
);
path = Backup;
sourceTree = "<group>";
Expand Down Expand Up @@ -16379,6 +16385,7 @@
DA5A850626C563A900F274C7 /* OAMultiselectableHeaderView.m in Sources */,
DA5A830E26C563A800F274C7 /* OATitleIconRoundCell.m in Sources */,
DA5A855A26C563A900F274C7 /* OAMapillaryContributeCard.m in Sources */,
46DD3CCD2CBD560F0087F8F0 /* LocalFileHashHelper.swift in Sources */,
323F04BE2C6532EF0058DD78 /* BaseRouteQuickAction.swift in Sources */,
DA5A824A26C563A700F274C7 /* OADefaultSpeedViewController.mm in Sources */,
DA5A846126C563A900F274C7 /* OAContextMenuLayer.mm in Sources */,
Expand Down Expand Up @@ -16903,6 +16910,7 @@
FAC166292B21BEF900D63755 /* CBUUIDPath.swift in Sources */,
FA359EE52ADF026D0001C11D /* DeviceType.swift in Sources */,
DA5A813A26C563A700F274C7 /* OAEntityInfo.m in Sources */,
462B6C782CB6C2C900DD6C7E /* BackupUtils.swift in Sources */,
DA5A846A26C563A900F274C7 /* OADestination.mm in Sources */,
464EA9BD2C4948A30034D8C9 /* PaletteGradientColor.swift in Sources */,
46220B792AD70AF9006C3248 /* OAGroupEditorViewController.mm in Sources */,
Expand Down
36 changes: 28 additions & 8 deletions Sources/AppHost/OsmAndAppImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,25 @@ - (void) migrateResourcesToDocumentsIfNeeded
{
BOOL movedRes = [self moveContentsOfDirectory:[_dataPath stringByAppendingPathComponent:RESOURCES_DIR]
toDest:[_documentsPath stringByAppendingPathComponent:RESOURCES_DIR]
removeOriginalFile:YES];
BOOL movedSqlite = [self moveContentsOfDirectory:[_dataPath stringByAppendingPathComponent:MAP_CREATOR_DIR]
removeOriginalFile:YES
saveHashes:NO];
BOOL movedSqlite = [self moveContentsOfDirectory:[_dataPath stringByAppendingPathComponent:MAP_CREATOR_DIR]
toDest:[_documentsPath stringByAppendingPathComponent:MAP_CREATOR_DIR]
removeOriginalFile:YES];
removeOriginalFile:YES
saveHashes:NO];
if (movedRes)
[self migrateMapNames:[_documentsPath stringByAppendingPathComponent:RESOURCES_DIR]];
if (movedRes || movedSqlite)
_resourcesManager->rescanUnmanagedStoragePaths(true);

[self moveContentsOfDirectory:[[NSBundle mainBundle] pathForResource:CLR_PALETTE_DIR ofType:nil]
toDest:_colorsPalettePath
removeOriginalFile:NO];
removeOriginalFile:NO
saveHashes:YES];
[self moveContentsOfDirectory:[[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:MODEL_3D_DIR]
toDest:[_documentsPath stringByAppendingPathComponent:MODEL_3D_DIR]
removeOriginalFile:NO];
removeOriginalFile:NO
saveHashes:NO];
}

- (BOOL) initializeCore
Expand Down Expand Up @@ -750,6 +754,7 @@ - (BOOL) initializeImpl
- (BOOL) moveContentsOfDirectory:(NSString *)src
toDest:(NSString *)dest
removeOriginalFile:(BOOL)remove
saveHashes:(BOOL)saveHashes
{
NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:src])
Expand All @@ -759,26 +764,36 @@ - (BOOL) moveContentsOfDirectory:(NSString *)src

NSArray *files = [fm contentsOfDirectoryAtPath:src error:nil];
BOOL tryAgain = NO;
LocalFileHashHelper *hashHelper = [LocalFileHashHelper shared];
for (NSString *file in files)
{
if ([fm fileExistsAtPath:[dest stringByAppendingPathComponent:file]])
NSString *destPath = [dest stringByAppendingPathComponent:file];
if ([fm fileExistsAtPath:destPath])
{
if (saveHashes)
[hashHelper setHash:destPath];
continue;
}
NSError *err = nil;
if (remove)
{
[fm moveItemAtPath:[src stringByAppendingPathComponent:file]
toPath:[dest stringByAppendingPathComponent:file]
toPath:destPath
error:&err];
}
else
{
[fm copyItemAtPath:[src stringByAppendingPathComponent:file]
toPath:[dest stringByAppendingPathComponent:file]
toPath:destPath
error:&err];
}
if (err)
tryAgain = YES;
if (saveHashes)
[hashHelper setHash:destPath];
}
if (saveHashes)
[hashHelper saveHashes];
if (remove && !tryAgain)
[fm removeItemAtPath:src error:nil];
return YES;
Expand Down Expand Up @@ -942,6 +957,11 @@ - (void) clearUnsupportedTilesCache
return builder;
}

- (void)rescanUnmanagedStoragePaths
{
_resourcesManager->rescanUnmanagedStoragePaths();
}

- (void) loadRoutingFiles
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Expand Down
1 change: 1 addition & 0 deletions Sources/AppHost/OsmAndAppProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
- (void) checkAndDownloadWeatherForecastsUpdates;

- (void) loadRoutingFiles;
- (void) rescanUnmanagedStoragePaths;

- (NSString *) favoritesStorageFilename:(NSString *)groupName;
- (NSString *) getGroupFileName:(NSString *)groupName;
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppHost/SceneDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ - (BOOL)handleIncomingOsmAndCloudURL:(NSURL *)url

if ([vc isKindOfClass:OACloudAccountVerificationViewController.class])
{
if ([OABackupHelper isTokenValid:tokenParam])
if ([BackupUtils isTokenValid:tokenParam])
{
[OABackupHelper.sharedInstance registerDevice:tokenParam];
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/Backup/BackupUiUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ final class BackupUiUtils: NSObject {
private static let minDurationForDateFormat = 48 * 60 * 60
private static let minDurationForYesterdayDateFormat = 24 * 60 * 60

static func getItemName(_ item: OASettingsItem) -> String {
static func getItemName(_ item: OASettingsItem?) -> String {
guard let item else { return localizedString("res_unknown") }

var name: String
if let profileItem = item as? OAProfileSettingsItem {
name = profileItem.appMode.toHumanString()
Expand All @@ -35,7 +37,9 @@ final class BackupUiUtils: NSObject {
return !name.isEmpty ? name : localizedString("res_unknown")
}

static func getIcon(_ item: OASettingsItem) -> UIImage? {
static func getIcon(_ item: OASettingsItem?) -> UIImage? {
guard let item else { return nil }

if let profileItem = item as? OAProfileSettingsItem {
return profileItem.appMode.getIcon()
}
Expand Down
Loading