<commit_before>#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MWMAlertViewController.h"
#import "MWMMapDownloaderViewController.h"
#import "MWMMigrationView.h"
#import "MWMMigrationViewController.h"
#import "MWMStorage.h"

#include "Framework.h"

#include "platform/platform.hpp"
#include "storage/storage.hpp"

namespace
{
NSString * const kDownloaderSegue = @"Migration2MapDownloaderSegue";
} // namespace

using namespace storage;

@implementation MWMMigrationViewController

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self configNavBar];
  [self checkState];
}

- (void)configNavBar
{
  self.title = L(@"download_maps");
}

- (void)checkState
{
  MWMMigrationView * mv = static_cast<MWMMigrationView *>(self.view);
  if (!GetFramework().IsEnoughSpaceForMigrate())
    mv.state = MWMMigrationViewState::ErrorNoSpace;
  else if (!Platform::IsConnected())
    mv.state = MWMMigrationViewState::ErrorNoConnection;
  else
    mv.state = MWMMigrationViewState::Default;
}

- (void)performLimitedMigration:(BOOL)limited
{
  auto & f = GetFramework();
  LocationManager * lm = [MapsAppDelegate theApp].m_locationManager;
  ms::LatLon position{};
  if (![lm getLat:position.lat Lon:position.lon])
    position = MercatorBounds::ToLatLon(f.GetViewportCenter());

  auto migrate = ^
  {
    GetFramework().Migrate(!limited);
    [self performSegueWithIdentifier:kDownloaderSegue sender:self];
  };

  auto onStatusChanged = [self, migrate](TCountryId const & countryId)
  {
    auto & f = GetFramework();
    auto s = f.Storage().GetPrefetchStorage();
    NodeAttrs nodeAttrs;
    s->GetNodeAttrs(countryId, nodeAttrs);
    switch (nodeAttrs.m_status)
    {
      case NodeStatus::OnDisk:
        migrate();
        break;
      case NodeStatus::Undefined:
      case NodeStatus::Error:
        [self showError:nodeAttrs.m_error countryId:countryId]; break;
      default:
        break;
    }
  };

  auto onProgressChanged = [](TCountryId const & countryId, TLocalAndRemoteSize const & progress){};

  if (f.PreMigrate(position, onStatusChanged, onProgressChanged))
    static_cast<MWMMigrationView *>(self.view).state = MWMMigrationViewState::Processing;
  else
    migrate();
}

- (void)showError:(NodeErrorCode)errorCode countryId:(TCountryId const &)countryId
{
  MWMAlertViewController * avc = self.alertController;
  switch (errorCode)
  {
    case NodeErrorCode::NoError:
      break;
    case NodeErrorCode::UnknownError:
      [avc presentInternalErrorAlert];
      break;
    case NodeErrorCode::OutOfMemFailed:
      [avc presentDownloaderNotEnoughSpaceAlert];
      break;
    case NodeErrorCode::NoInetConnection:
      [avc presentDownloaderNoConnectionAlertWithOkBlock:^
      {
        [MWMStorage retryDownloadNode:countryId];
      }];
      break;
  }
}

#pragma mark - Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([segue.identifier isEqualToString:kDownloaderSegue])
  {
    MWMMapDownloaderViewController * dvc = segue.destinationViewController;
    dvc.parentCountryId = GetFramework().Storage().GetRootId();
  }<commit_msg>[ios] Disabled migration controller back button on migration.<commit_after>#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MWMAlertViewController.h"
#import "MWMMapDownloaderViewController.h"
#import "MWMMigrationView.h"
#import "MWMMigrationViewController.h"
#import "MWMStorage.h"

#include "Framework.h"

#include "platform/platform.hpp"
#include "storage/storage.hpp"

namespace
{
NSString * const kDownloaderSegue = @"Migration2MapDownloaderSegue";
} // namespace

using namespace storage;

@implementation MWMMigrationViewController

- (void)viewDidLoad
{
  [super viewDidLoad];
  [self configNavBar];
  [self checkState];
}

- (void)configNavBar
{
  self.title = L(@"download_maps");
}

- (void)checkState
{
  if (!GetFramework().IsEnoughSpaceForMigrate())
    [self setState:MWMMigrationViewState::ErrorNoSpace];
  else if (!Platform::IsConnected())
    [self setState:MWMMigrationViewState::ErrorNoConnection];
  else
    [self setState:MWMMigrationViewState::Default];
}

- (void)performLimitedMigration:(BOOL)limited
{
  auto & f = GetFramework();
  LocationManager * lm = [MapsAppDelegate theApp].m_locationManager;
  ms::LatLon position{};
  if (![lm getLat:position.lat Lon:position.lon])
    position = MercatorBounds::ToLatLon(f.GetViewportCenter());

  auto migrate = ^
  {
    GetFramework().Migrate(!limited);
    [self performSegueWithIdentifier:kDownloaderSegue sender:self];
  };

  auto onStatusChanged = [self, migrate](TCountryId const & countryId)
  {
    auto & f = GetFramework();
    auto s = f.Storage().GetPrefetchStorage();
    NodeAttrs nodeAttrs;
    s->GetNodeAttrs(countryId, nodeAttrs);
    switch (nodeAttrs.m_status)
    {
      case NodeStatus::OnDisk:
        migrate();
        break;
      case NodeStatus::Undefined:
      case NodeStatus::Error:
        [self showError:nodeAttrs.m_error countryId:countryId]; break;
      default:
        break;
    }
  };

  auto onProgressChanged = [](TCountryId const & countryId, TLocalAndRemoteSize const & progress){};

  if (f.PreMigrate(position, onStatusChanged, onProgressChanged))
    [self setState:MWMMigrationViewState::Processing];
  else
    migrate();
}

- (void)showError:(NodeErrorCode)errorCode countryId:(TCountryId const &)countryId
{
  MWMAlertViewController * avc = self.alertController;
  switch (errorCode)
  {
    case NodeErrorCode::NoError:
      break;
    case NodeErrorCode::UnknownError:
      [avc presentInternalErrorAlert];
      break;
    case NodeErrorCode::OutOfMemFailed:
      [avc presentDownloaderNotEnoughSpaceAlert];
      break;
    case NodeErrorCode::NoInetConnection:
      [avc presentDownloaderNoConnectionAlertWithOkBlock:^
      {
        [MWMStorage retryDownloadNode:countryId];
      }];
      break;
  }
}

- (void)setState:(MWMMigrationViewState)state
{
  static_cast<MWMMigrationView *>(self.view).state = state;
  self.navigationItem.leftBarButtonItem.enabled = (state != MWMMigrationViewState::Processing);
}

#pragma mark - Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([segue.identifier isEqualToString:kDownloaderSegue])
  {
    MWMMapDownloaderViewController * dvc = segue.destinationViewController;
    dvc.parentCountryId = GetFramework().Storage().GetRootId();
  }
{'fraction_non_alphanumeric': 0.11772092293203579, 'fraction_numerical': 0.0003139224611520954, 'mean_word_length': 4.689285714285714, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5710345', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2003, 'n_words': 353}