visual_studio_validator.dart 1.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../base/context.dart';
import '../base/user_messages.dart';
import '../doctor.dart';
import 'visual_studio.dart';

VisualStudioValidator get visualStudioValidator => context.get<VisualStudioValidator>();

class VisualStudioValidator extends DoctorValidator {
  const VisualStudioValidator() : super('Visual Studio - develop for Windows');

  @override
  Future<ValidationResult> validate() async {
    final List<ValidationMessage> messages = <ValidationMessage>[];
    ValidationType status = ValidationType.missing;
    String versionInfo;

    if (visualStudio.isInstalled) {
      status = ValidationType.installed;

      messages.add(ValidationMessage(
          userMessages.visualStudioLocation(visualStudio.installLocation)
      ));

      messages.add(ValidationMessage(userMessages.visualStudioVersion(
          visualStudio.displayName,
          visualStudio.fullVersion,
      )));

      if (!visualStudio.hasNecessaryComponents) {
        status = ValidationType.partial;
        final int majorVersion = int.tryParse(visualStudio.fullVersion.split('.')[0]);
        messages.add(ValidationMessage.error(
            userMessages.visualStudioMissingComponents(
                visualStudio.workloadDescription,
                visualStudio.necessaryComponentDescriptions(majorVersion)
            )
        ));
      }
      versionInfo = '${visualStudio.displayName} ${visualStudio.displayVersion}';
    } else {
      status = ValidationType.missing;
      messages.add(ValidationMessage.error(userMessages.visualStudioMissing));
    }

    return ValidationResult(status, messages, statusInfo: versionInfo);
  }
}