<commit_before>//
//  ExternalResourcesProvider.cpp
//  OsmAnd
//
//  Created by <NAME> on 12/8/13.
//  Copyright (c) 2013 OsmAnd. All rights reserved.
//

#include "ExternalResourcesProvider.h"

#include <QStringList>
#include <QFile>

#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>

ExternalResourcesProvider::ExternalResourcesProvider(const bool useHD_)
    : useHD(useHD_)
{
}

ExternalResourcesProvider::~ExternalResourcesProvider()
{
}

QByteArray ExternalResourcesProvider::getResource(const QString& name, bool* ok /*= nullptr*/) const
{
    if(!useHD)
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    
    auto resourceFileName = name;
    resourceFileName = resourceFileName.replace(QLatin1String("map/shaders/"), QLatin1String("h_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/map_icons/"), QLatin1String("mm_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/shields/"), QLatin1String("h_"));
    const auto fileNameParts = resourceFileName.split('.');
    const auto resourcePath = [[NSBundle mainBundle]
                               pathForResource:[NSString stringWithUTF8String:fileNameParts[0].toUtf8().constData()]
                               ofType:[NSString stringWithUTF8String:fileNameParts[1].toUtf8().constData()]
                               inDirectory:@"Embedded/HD"];
    if(resourcePath == nil)
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    
    QFile resourceFile(QString::fromUtf8([resourcePath UTF8String]));
    if(!resourceFile.exists())
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    if(!resourceFile.open(QIODevice::ReadOnly))
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    
    const auto data = resourceFile.readAll();
    resourceFile.close();

    if(ok)
        *ok = true;
    return data;
}

bool ExternalResourcesProvider::containsResource(const QString& name) const
{
    if(!useHD)
        return false;
    
    auto resourceFileName = name;
    resourceFileName = resourceFileName.replace(QLatin1String("map/shaders/"), QLatin1String("h_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/map_icons/"), QLatin1String("mm_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/shields/"), QLatin1String("h_"));
    const auto fileNameParts = resourceFileName.split('.');
    const auto resourcePath = [[NSBundle mainBundle]
                               pathForResource:[NSString stringWithUTF8String:fileNameParts[0].toUtf8().constData()]
                               ofType:[NSString stringWithUTF8String:fileNameParts[1].toUtf8().constData()]
                               inDirectory:@"Embedded/HD"];
    
    return (resourcePath != nil);
}
<commit_msg>Fix resources path<commit_after>//
//  ExternalResourcesProvider.cpp
//  OsmAnd
//
//  Created by <NAME> on 12/8/13.
//  Copyright (c) 2013 OsmAnd. All rights reserved.
//

#include "ExternalResourcesProvider.h"

#include <QStringList>
#include <QFile>

#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>

ExternalResourcesProvider::ExternalResourcesProvider(const bool useHD_)
    : useHD(useHD_)
{
}

ExternalResourcesProvider::~ExternalResourcesProvider()
{
}

QByteArray ExternalResourcesProvider::getResource(const QString& name, bool* ok /*= nullptr*/) const
{
    if(!useHD)
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    
    auto resourceFileName = name;
    resourceFileName = resourceFileName.replace(QLatin1String("map/shaders/"), QLatin1String("h_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/map_icons/"), QLatin1String("mm_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/shields/"), QLatin1String("h_"));
    const auto fileNameParts = resourceFileName.split('.');
    const auto resourcePath = [[NSBundle mainBundle]
                               pathForResource:[NSString stringWithUTF8String:fileNameParts[0].toUtf8().constData()]
                               ofType:[NSString stringWithUTF8String:fileNameParts[1].toUtf8().constData()]
                               inDirectory:@"drawable-xhdpi"];
    if(resourcePath == nil)
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    
    QFile resourceFile(QString::fromUtf8([resourcePath UTF8String]));
    if(!resourceFile.exists())
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    if(!resourceFile.open(QIODevice::ReadOnly))
    {
        if(ok)
            *ok = false;
        return QByteArray();
    }
    
    const auto data = resourceFile.readAll();
    resourceFile.close();

    if(ok)
        *ok = true;
    return data;
}

bool ExternalResourcesProvider::containsResource(const QString& name) const
{
    if(!useHD)
        return false;
    
    auto resourceFileName = name;
    resourceFileName = resourceFileName.replace(QLatin1String("map/shaders/"), QLatin1String("h_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/map_icons/"), QLatin1String("mm_"));
    resourceFileName = resourceFileName.replace(QLatin1String("map/shields/"), QLatin1String("h_"));
    const auto fileNameParts = resourceFileName.split('.');
    const auto resourcePath = [[NSBundle mainBundle]
                               pathForResource:[NSString stringWithUTF8String:fileNameParts[0].toUtf8().constData()]
                               ofType:[NSString stringWithUTF8String:fileNameParts[1].toUtf8().constData()]
                               inDirectory:@"drawable-xhdpi"];
    
    return (resourcePath != nil);
}

{'fraction_non_alphanumeric': 0.12619171433524007, 'fraction_numerical': 0.012133818686080777, 'mean_word_length': 2.9710942876806605, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707115', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1646, 'n_words': 280}