Compare commits
2 Commits
dev
...
dart-git-v
Author | SHA1 | Date |
---|---|---|
Calcitem | 67a4b23268 | |
Calcitem | 9e06ca51f8 |
|
@ -22,6 +22,8 @@ import 'package:sanmill/style/app_theme.dart';
|
|||
import 'settings.dart';
|
||||
|
||||
class Config {
|
||||
static bool settingsLoaded = false;
|
||||
|
||||
static bool toneEnabled = true;
|
||||
static int thinkingTime = 10000; // TODO: waitResponse
|
||||
static bool aiMovesFirst = false;
|
||||
|
@ -123,6 +125,7 @@ class Config {
|
|||
rule.maxStepsLedToDraw =
|
||||
Config.maxStepsLedToDraw = settings['MaxStepsLedToDraw'] ?? 50;
|
||||
|
||||
settingsLoaded = true;
|
||||
print("Loading settings done!");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Michael Mitterer (office@mikemitterer.at),
|
||||
* IT-Consulting and Development Limited.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// Reads GIT version information
|
||||
library git_version;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
final Logger _logger = new Logger('git_version');
|
||||
|
||||
const String ERROR_NO_VERSION_TAG =
|
||||
"No version-Tag found! (Tagname must start with 'v|V[0-9]')";
|
||||
|
||||
// GIT Parts wurden von
|
||||
// https://github.com/kevmoo/git.dart/blob/master/lib/src/top_level.dart
|
||||
// übernommen
|
||||
final _gitBinName = "C:\\Program Files\\Git\\bin\\git.exe";
|
||||
|
||||
/// Runs the 'git' command
|
||||
Future<ProcessResult> runGit(final List<String> args,
|
||||
{bool throwOnError: true, String? processWorkingDir}) async {
|
||||
final git = _gitBinName;
|
||||
|
||||
final result = await Process.run(git, args,
|
||||
workingDirectory: processWorkingDir, runInShell: true);
|
||||
|
||||
if (throwOnError) {
|
||||
_throwIfProcessFailed(result, git, args);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns a list of all the available git tags
|
||||
///
|
||||
/// The tags are sorted by 'version:refname'
|
||||
/// More: https://git-scm.com/docs/git-tag
|
||||
Future<List<String>> getSortedGitTags() async {
|
||||
final ProcessResult result =
|
||||
await runGit(<String>["tag", "-l", "--sort=v:refname"]);
|
||||
return result.stdout.toString().split("\n");
|
||||
}
|
||||
|
||||
Future<String> getGitRevision() async {
|
||||
// git rev-list HEAD -n 1
|
||||
final ProcessResult result =
|
||||
await runGit(<String>["rev-list", "HEAD", "-n1"]);
|
||||
return result.stdout.toString();
|
||||
}
|
||||
|
||||
/// Returns all tags starting with [v|V][0-9]
|
||||
List<String>? getVersionTags(final List<String> tags) {
|
||||
if (tags.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return tags
|
||||
.where((tag) => tag.startsWith(new RegExp(r'^[v|V][0-9]')))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// The command finds the most recent tag that is reachable from a commit.
|
||||
///
|
||||
/// If the tag points to the commit, then only the tag is shown.
|
||||
/// Otherwise, it suffixes the tag name with the number of additional commits
|
||||
/// on top of the tagged object and the abbreviated object name of the
|
||||
/// most recent commit.
|
||||
///
|
||||
/// More: https://git-scm.com/docs/git-describe
|
||||
Future<String> describeTag(final String tag) async {
|
||||
final ProcessResult result =
|
||||
await runGit(<String>["describe", "--tags", "--match", tag]);
|
||||
return result.stdout.toString().trim();
|
||||
}
|
||||
|
||||
/// Converts GIT extended Format (v0.2-204-g507e9bc) to version
|
||||
///
|
||||
/// If [removeDash] is set to true the dash will be replace by a dot. e.g. 0.1-33 -> 0.1.33
|
||||
String extendedFormatToVersion(final String versionFromGit,
|
||||
{final String patchDelimiter = "."}) {
|
||||
final RegExp patchVersion = new RegExp(r"([^.]*)\.([^-]*)-([^-]*)-(.*)");
|
||||
|
||||
String version = versionFromGit.replaceFirst(new RegExp(r"^[v|V]"), "");
|
||||
_logger.fine("Git-Version: $version");
|
||||
|
||||
// So was: v0.3-1-g179fe76
|
||||
if (patchVersion.hasMatch(version)) {
|
||||
version = version.replaceAllMapped(patchVersion, (final Match m) {
|
||||
return "${m[1]}.${m[2]}$patchDelimiter${m[3]}";
|
||||
});
|
||||
}
|
||||
// oder so v0.3-g179fe76
|
||||
else {
|
||||
version = version.replaceAllMapped(new RegExp(r"([^.]*)\.([^-]*)-(.*)"),
|
||||
(final Match m) {
|
||||
return "${m[1]}.${m[2]}";
|
||||
});
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
void _throwIfProcessFailed(
|
||||
ProcessResult? pr, String process, List<String> args) {
|
||||
assert(pr != null);
|
||||
if (pr!.exitCode != 0) {
|
||||
var message =
|
||||
'''
|
||||
stdout:
|
||||
${pr.stdout}
|
||||
stderr:
|
||||
${pr.stderr}'''
|
||||
.replaceAll(new RegExp(r'^\s*', multiLine: true), "");
|
||||
|
||||
throw new ProcessException(process, args, "\n$message", pr.exitCode);
|
||||
}
|
||||
}
|
|
@ -109,6 +109,11 @@ class NativeEngine extends AiEngine {
|
|||
}
|
||||
|
||||
Future<void> setOptions() async {
|
||||
if (Config.settingsLoaded == false) {
|
||||
print("Settings is not loaded yet.");
|
||||
await Config.loadSettings();
|
||||
}
|
||||
|
||||
await send('setoption name SkillLevel value ${Config.skillLevel}');
|
||||
await send('setoption name AiIsLazy value ${Config.aiIsLazy}');
|
||||
await send('setoption name Shuffling value ${Config.shufflingEnabled}');
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:sanmill/common/git_version.dart';
|
||||
import 'package:catcher/catcher.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
@ -27,14 +28,15 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:sanmill/generated/l10n.dart';
|
||||
import 'package:sanmill/style/app_theme.dart';
|
||||
import 'package:sanmill/widgets/navigation_home_screen.dart';
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'common/config.dart';
|
||||
import 'services/audios.dart';
|
||||
|
||||
//import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
String ver = await getGitRevision();
|
||||
print("Git Revision: $ver");
|
||||
|
||||
if (!(Platform.isAndroid || Platform.isIOS)) {
|
||||
runApp(SanmillApp());
|
||||
return;
|
||||
|
@ -127,12 +129,8 @@ class SanmillApp extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _SanmillAppState extends State<SanmillApp> {
|
||||
//
|
||||
@override
|
||||
void initState() {
|
||||
Chain.capture(() {
|
||||
Config.loadSettings();
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ dependencies:
|
|||
catcher: ^0.6.3
|
||||
stack_trace: ^1.10.0
|
||||
device_info_plus_platform_interface: ^1.0.1
|
||||
build: ^2.0.0
|
||||
where: ^4.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue