<commit_before>//
//  OsmAndAppImpl.m
//  OsmAnd
//
//  Created by <NAME> on 2/25/14.
//  Copyright (c) 2014 OsmAnd. All rights reserved.
//

#import "OsmAndAppImpl.h"

#include <algorithm>

#include <QStandardPaths>
#include <QList>

#include <OsmAndCore.h>
#include <OsmAndCore/Data/ObfFile.h>
#include <OsmAndCore/Data/ObfReader.h>

@implementation OsmAndAppImpl
{
    std::shared_ptr<OsmAnd::ObfFile> _worldMiniBasemap;
    QString _documentsPath;
    QString _cachePath;
}

@synthesize obfsCollection = _obfsCollection;
@synthesize mapStyles = _mapStyles;

- (id)init
{
    self = [super init];
    if (self) {
        [self ctor];
    }
    return self;
}

#define kAppData @"app_data"

- (void)ctor
{
    // First of all, initialize user defaults
    [self initUserDefaults];

    // Unpack app data
    _data = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:kAppData]];

    // Get location of a shipped world mini-basemap and it's version stamp
    NSString* worldMiniBasemapFilename = [[NSBundle mainBundle] pathForResource:@"WorldMiniBasemap"
                                                        ofType:@"obf"
                                                   inDirectory:@"Shipped"];
    NSString* worldMiniBasemapStamp = [[NSBundle mainBundle] pathForResource:@"WorldMiniBasemap.obf"
                                                                      ofType:@"stamp"
                                                                 inDirectory:@"Shipped"];
    NSError* versionError = nil;
    NSString* worldMiniBasemapStampContents = [NSString stringWithContentsOfFile:worldMiniBasemapStamp
                                                                  encoding:NSASCIIStringEncoding
                                                                     error:&versionError];
    NSString* worldMiniBasemapVersion = [worldMiniBasemapStampContents stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSLog(@"Located shipped world mini-basemap (version %@) at %@", worldMiniBasemapVersion, worldMiniBasemapFilename);
    _worldMiniBasemap.reset(new OsmAnd::ObfFile(QString::fromNSString(worldMiniBasemapFilename)));
    
    // Get default paths
    _documentsPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
    NSLog(@"Documents path: %s", qPrintable(_documentsPath));
    _cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
    NSLog(@"Cache path: %s", qPrintable(_cachePath));
    
    [self initObfsCollection];
    [self initMapStyles];
    
    _mapModeObservable = [[OAObservable alloc] init];
    
    _locationServices = [[OALocationServices alloc] initWith:self];
    if(_locationServices.available && _locationServices.allowed)
        [_locationServices start];
}

- (void)initObfsCollection
{
    _obfsCollection.reset(new OsmAnd::ObfsCollection());
    
    // Set modifier to add world mini-basemap if there's no other basemap available
    _obfsCollection->setSourcesSetModifier([self](const OsmAnd::ObfsCollection& collection, QList< std::shared_ptr<OsmAnd::ObfReader> >& inOutSources)
    {
        const auto basemapPresent = std::any_of(inOutSources.cbegin(), inOutSources.cend(), [](const std::shared_ptr<OsmAnd::ObfReader>& obfReader)
        {
            return obfReader->obtainInfo()->isBasemap;
        });
        
        // If there's no basemap present, add mini-basemap
        if(!basemapPresent)
            inOutSources.push_back(std::shared_ptr<OsmAnd::ObfReader>(new OsmAnd::ObfReader(_worldMiniBasemap)));
    });
    
    // Register "Documents" directory (which is accessible from iTunes)
    _obfsCollection->registerDirectory(_documentsPath);
}

- (void)initUserDefaults
{
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

    // Register defaults
    [userDefaults registerDefaults:[self inflateInitialUserDefaults]];
}

- (NSDictionary*)inflateInitialUserDefaults
{
    NSMutableDictionary* initialUserDefaults = [[NSMutableDictionary alloc] init];

    [initialUserDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:[OAAppData defaults]]]
                            forKey:kAppData];

    return initialUserDefaults;
}

- (void)initMapStyles
{
    _mapStyles.reset(new OsmAnd::MapStyles());
}

@synthesize data = _data;<commit_msg>Fix build<commit_after>//
//  OsmAndAppImpl.m
//  OsmAnd
//
//  Created by <NAME> on 2/25/14.
//  Copyright (c) 2014 OsmAnd. All rights reserved.
//

#import "OsmAndAppImpl.h"

#include <algorithm>

#include <QStandardPaths>
#include <QList>

#include <OsmAndCore.h>
#include <OsmAndCore/Data/ObfFile.h>
#include <OsmAndCore/Data/ObfReader.h>

@implementation OsmAndAppImpl
{
    std::shared_ptr<OsmAnd::ObfFile> _worldMiniBasemap;
    QString _documentsPath;
    QString _cachePath;
}

@synthesize obfsCollection = _obfsCollection;
@synthesize mapStyles = _mapStyles;

- (id)init
{
    self = [super init];
    if (self) {
        [self ctor];
    }
    return self;
}

#define kAppData @"app_data"

- (void)ctor
{
    // First of all, initialize user defaults
    [self initUserDefaults];

    // Unpack app data
    _data = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:kAppData]];

    // Get location of a shipped world mini-basemap and it's version stamp
    NSString* worldMiniBasemapFilename = [[NSBundle mainBundle] pathForResource:@"WorldMiniBasemap"
                                                        ofType:@"obf"
                                                   inDirectory:@"Shipped"];
    NSString* worldMiniBasemapStamp = [[NSBundle mainBundle] pathForResource:@"WorldMiniBasemap.obf"
                                                                      ofType:@"stamp"
                                                                 inDirectory:@"Shipped"];
    NSError* versionError = nil;
    NSString* worldMiniBasemapStampContents = [NSString stringWithContentsOfFile:worldMiniBasemapStamp
                                                                  encoding:NSASCIIStringEncoding
                                                                     error:&versionError];
    NSString* worldMiniBasemapVersion = [worldMiniBasemapStampContents stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSLog(@"Located shipped world mini-basemap (version %@) at %@", worldMiniBasemapVersion, worldMiniBasemapFilename);
    _worldMiniBasemap.reset(new OsmAnd::ObfFile(QString::fromNSString(worldMiniBasemapFilename)));
    
    // Get default paths
    _documentsPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
    NSLog(@"Documents path: %s", qPrintable(_documentsPath));
    _cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
    NSLog(@"Cache path: %s", qPrintable(_cachePath));
    
    [self initObfsCollection];
    [self initMapStyles];
    
    _mapModeObservable = [[OAObservable alloc] init];
    
    _locationServices = [[OALocationServices alloc] initWith:self];
    if(_locationServices.available && _locationServices.allowed)
        [_locationServices start];
}

- (void)initObfsCollection
{
    _obfsCollection.reset(new OsmAnd::ObfsCollection());
    
    // Set modifier to add world mini-basemap if there's no other basemap available
    _obfsCollection->setSourcesSetModifier([self](const OsmAnd::ObfsCollection& collection, QList< std::shared_ptr<OsmAnd::ObfReader> >& inOutSources)
    {
        const auto basemapPresent = std::any_of(inOutSources.cbegin(), inOutSources.cend(), [](const std::shared_ptr<OsmAnd::ObfReader>& obfReader)
        {
            return obfReader->obtainInfo()->isBasemap;
        });
        
        // If there's no basemap present, add mini-basemap
        if(!basemapPresent)
            inOutSources.push_back(std::shared_ptr<OsmAnd::ObfReader>(new OsmAnd::ObfReader(_worldMiniBasemap)));
    });
    
    // Register "Documents" directory (which is accessible from iTunes)
    _obfsCollection->registerDirectory(_documentsPath);
}

- (void)initUserDefaults
{
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

    // Register defaults
    [userDefaults registerDefaults:[self inflateInitialUserDefaults]];
}

- (NSDictionary*)inflateInitialUserDefaults
{
    NSMutableDictionary* initialUserDefaults = [[NSMutableDictionary alloc] init];

    [initialUserDefaults setValue:[NSKeyedArchiver archivedDataWithRootObject:[OAAppData defaults]]
                            forKey:kAppData];

    return initialUserDefaults;
}

- (void)initMapStyles
{
    _mapStyles.reset(new OsmAnd::MapStyles());
}

@synthesize data = _data;
{'fraction_non_alphanumeric': 0.1017162471395881, 'fraction_numerical': 0.002059496567505721, 'mean_word_length': 3.050509731232623, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866160', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2495, 'n_words': 464}