Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
committed Feb 10, 2025
1 parent 5c5f792 commit 01a9656
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 76 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.65

- New Version 0.0.65
- Update Dependencies
## 0.0.64

- New Version 0.0.64
Expand Down
1 change: 1 addition & 0 deletions dev/pub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions example/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 10 additions & 21 deletions lib/asii_tree/ascii_tree.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// A simple library for rendering tree-like structures in Unicode symbols with
/// a fallback to ASCII.
library;


import 'dart:io';

Expand Down Expand Up @@ -91,14 +85,17 @@ List<T> _ordered<T extends Comparable<T>>(Iterable<T> iter) {

/// Gets a _emoji special character as unicode, or the [alternative] if unicode
/// characters are not supported by stdout.
String _emoji(String unicode, String alternative) => _canUseUnicode ? unicode : alternative;
String _emoji(String unicode, String alternative) =>
_canUseUnicode ? unicode : alternative;

// Assume unicode _emojis are supported when not on Windows.
// If we are on Windows, unicode _emojis are supported in Windows Terminal,
// which sets the WT_SESSION environment variable. See:
// https://github.com/microsoft/terminal/blob/master/doc/user-docs/index.md#tips-and-tricks
bool get _canUseUnicode => !Platform.isWindows || Platform.environment.containsKey('WT_SESSION');
bool get _canUseUnicode =>
!Platform.isWindows || Platform.environment.containsKey('WT_SESSION');

/// GeneralLib
class AsciiTree {
/// Draws a tree for the given list of files
///
Expand Down Expand Up @@ -155,7 +152,8 @@ class AsciiTree {
// Parse out the files into a tree of nested maps.
final root = <String, Map>{};
for (var file in files) {
final relativeFile = baseDir == null ? file : p.relative(file, from: baseDir);
final relativeFile =
baseDir == null ? file : p.relative(file, from: baseDir);
final parts = p.split(relativeFile);
if (showFileSizes) {
final stat = File(p.normalize(file)).statSync();
Expand All @@ -167,7 +165,8 @@ class AsciiTree {
}
var directory = root;
for (var part in parts) {
directory = directory.putIfAbsent(part, () => <String, Map>{}) as Map<String, Map>;
directory = directory.putIfAbsent(part, () => <String, Map>{})
as Map<String, Map>;
}
}

Expand Down Expand Up @@ -210,13 +209,3 @@ class AsciiTree {
return buffer.toString();
}
}

void main(List<String> args) {
final Directory directory = Directory(p.join(Directory.current.path, "lib", "dart"));
String data = AsciiTree.fromFiles(
directory.listSync(recursive: true).map((e) => e.path).toList(),
baseDir: directory.path,
showFileSizes: true,
);
print(data);
}
31 changes: 20 additions & 11 deletions lib/dart/dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class Dart {
static bool get isMobile => Dart.isAndroid || Dart.isIOS;

/// GeneralLib
static bool get isDesktop => Dart.isLinux || Dart.isMacOS || Dart.isWindows || Dart.isFuchsia;
static bool get isDesktop =>
Dart.isLinux || Dart.isMacOS || Dart.isWindows || Dart.isFuchsia;

/// GeneralLib
Expand Down Expand Up @@ -165,32 +166,38 @@ class Dart {

/// GeneralLib
static Future<String?> networkLocalIpAddres() async {
final interfaces = await NetworkInterface.list(type: InternetAddressType.IPv4, includeLinkLocal: true);
final interfaces = await NetworkInterface.list(
type: InternetAddressType.IPv4, includeLinkLocal: true);
try {
NetworkInterface? interface = interfaces.singleWhereOrNull((element) => RegExp("^(wl)", caseSensitive: false).hasMatch(element.name));
NetworkInterface? interface = interfaces.singleWhereOrNull((element) =>
RegExp("^(wl)", caseSensitive: false).hasMatch(element.name));
if (interface != null) {
return interface.addresses.first.address;
}
try {
NetworkInterface interface = interfaces.firstWhere((element) => element.name == "eth0");
NetworkInterface interface =
interfaces.firstWhere((element) => element.name == "eth0");
return interface.addresses.first.address;
} catch (e) {
// Try any other connection next
try {
NetworkInterface interface = interfaces.firstWhere((element) => !(["wlan0"].contains(element.name)));
NetworkInterface interface = interfaces
.firstWhere((element) => !(["wlan0"].contains(element.name)));
return interface.addresses.first.address;
} catch (ex) {
return null;
}
}
} catch (ex) {
try {
NetworkInterface interface = interfaces.firstWhere((element) => element.name == "eth0");
NetworkInterface interface =
interfaces.firstWhere((element) => element.name == "eth0");
return interface.addresses.first.address;
} catch (e) {
// Try any other connection next
try {
NetworkInterface interface = interfaces.firstWhere((element) => !(["wlan0"].contains(element.name)));
NetworkInterface interface = interfaces
.firstWhere((element) => !(["wlan0"].contains(element.name)));
return interface.addresses.first.address;
} catch (ex) {
return null;
Expand All @@ -217,11 +224,13 @@ class Dart {
}
String? configDir;
if (Platform.isLinux) {
configDir = path.join(Platform.environment['XDG_CONFIG_HOME'] ?? Platform.environment['HOME']!);
configDir = path.join(Platform.environment['XDG_CONFIG_HOME'] ??
Platform.environment['HOME']!);
} else if (Platform.isWindows) {
configDir = Platform.environment['APPDATA']!;
} else if (Platform.isMacOS) {
configDir = path.join(Platform.environment['HOME']!, 'Library', 'Application Support');
configDir = path.join(
Platform.environment['HOME']!, 'Library', 'Application Support');
} else {
configDir = path.join(Platform.environment['HOME'] ?? '');
}
Expand All @@ -230,10 +239,10 @@ class Dart {

/// recomendation used threads
/// minimal 1
static int maxProcessorsUseRecommendation() {
static int maxProcessorsUseRecommendation() {
return math.max((Platform.numberOfProcessors - 1) / 4, 1).toInt();
}

/// recomendation used threads
/// minimal 1
static int maxThreadsProcessorsUseRecommendation() {
Expand Down
67 changes: 48 additions & 19 deletions lib/dart/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,17 @@ class Pub {
if (Dart.isWeb) {
return null;
}
final File file_pubspec = File(path.join(directoryPackage.path, "pubspec.yaml"));
final File file_pubspec =
File(path.join(directoryPackage.path, "pubspec.yaml"));
if (file_pubspec.existsSync() == false) {
return null;
}
final Map yaml_code = (yaml.loadYaml(file_pubspec.readAsStringSync(), recover: true) as Map);
final Map yaml_code =
(yaml.loadYaml(file_pubspec.readAsStringSync(), recover: true) as Map);
// /home/galaxeus/.pub-cache/hosted/pub.dev/.cache/telegram_client-versions.json
{
final File file_pub_dev_versions = File(path.join(hosted_directory.path, "pub.dev", ".cache", "${yaml_code["name"]}-versions.json"));
final File file_pub_dev_versions = File(path.join(hosted_directory.path,
"pub.dev", ".cache", "${yaml_code["name"]}-versions.json"));
if (file_pub_dev_versions.parent.existsSync() == false) {
file_pub_dev_versions.parent.createSync(recursive: true);
}
Expand All @@ -150,7 +153,9 @@ class Pub {
}
{
try {
final fetchedAt = DateTime.tryParse(jsonPubDevVersion["_fetchedAt"]) ?? DateTime.now();
final fetchedAt =
DateTime.tryParse(jsonPubDevVersion["_fetchedAt"]) ??
DateTime.now();
jsonPubDevVersion["_fetchedAt"] = fetchedAt.toIso8601String();
} catch (e) {
jsonPubDevVersion["_fetchedAt"] = DateTime.now().toIso8601String();
Expand All @@ -160,7 +165,9 @@ class Pub {
final String archive_sha256 = () {
final String archive_sha256 = (archiveSha256 ?? "").trim();
if (jsonPubDevVersion["latest"] is Map) {
if (jsonPubDevVersion["latest"]["archive_sha256"] is String && (jsonPubDevVersion["latest"]["archive_sha256"] as String).isNotEmpty) {
if (jsonPubDevVersion["latest"]["archive_sha256"] is String &&
(jsonPubDevVersion["latest"]["archive_sha256"] as String)
.isNotEmpty) {
return jsonPubDevVersion["latest"]["archive_sha256"];
}
}
Expand All @@ -170,16 +177,21 @@ class Pub {
return archive_sha256;
}();
{
final File file_pub_dev_hash = File(path.join(hosted_hashes_directory.path, "pub.dev", "${yaml_code["name"]}-${yaml_code["version"]}.sha256"));
final File file_pub_dev_hash = File(path.join(
hosted_hashes_directory.path,
"pub.dev",
"${yaml_code["name"]}-${yaml_code["version"]}.sha256"));
if (file_pub_dev_hash.parent.existsSync() == false) {
file_pub_dev_hash.parent.createSync(recursive: true);
}
file_pub_dev_hash.writeAsStringSync(archive_sha256);
}
final String published = () {
final DateTime dateTimeBefore = DateTime.now().subtract(Duration(minutes: 10));
final DateTime dateTimeBefore =
DateTime.now().subtract(Duration(minutes: 10));
if (jsonPubDevVersion["latest"] is Map) {
if (jsonPubDevVersion["latest"]["published"] is String && (jsonPubDevVersion["latest"]["published"] as String).isNotEmpty) {
if (jsonPubDevVersion["latest"]["published"] is String &&
(jsonPubDevVersion["latest"]["published"] as String).isNotEmpty) {
return jsonPubDevVersion["latest"]["published"];
}
}
Expand All @@ -189,7 +201,8 @@ class Pub {
final Map latest_pub_dev_version = {
"version": yaml_code["version"],
"pubspec": yaml_code,
"archive_url": "https://pub.dev/api/archives/${yaml_code["name"]}-${yaml_code["version"]}.tar.gz",
"archive_url":
"https://pub.dev/api/archives/${yaml_code["name"]}-${yaml_code["version"]}.tar.gz",
"archive_sha256": archive_sha256,
"published": published,
};
Expand All @@ -207,7 +220,8 @@ class Pub {
for (int i = 0; i < pub_dev_package_versions.length; i++) {
final pub_dev_package_version = pub_dev_package_versions[i];
if (pub_dev_package_version is Map) {
if (pub_dev_package_version["version"] == latest_pub_dev_version["version"]) {
if (pub_dev_package_version["version"] ==
latest_pub_dev_version["version"]) {
pub_dev_package_versions[i] = latest_pub_dev_version;

isNotFoundUpdate = false;
Expand All @@ -223,7 +237,10 @@ class Pub {
jsonPubDevVersion["versions"] = pub_dev_package_versions;
file_pub_dev_versions.writeAsStringSync(json.encode(jsonPubDevVersion));
}
final Directory directory_pub_dev = Directory(path.join(hosted_directory.path, "pub.dev", "${yaml_code["name"]}-${yaml_code["version"]}"));
final Directory directory_pub_dev = Directory(path.join(
hosted_directory.path,
"pub.dev",
"${yaml_code["name"]}-${yaml_code["version"]}"));
if (deleteIfExist && directory_pub_dev.existsSync()) {
directory_pub_dev.deleteSync(recursive: true);
directory_pub_dev.createSync(recursive: true);
Expand All @@ -242,15 +259,18 @@ class Pub {
if (Dart.isWeb) {
return null;
}
final File file_pubspec = File(path.join(directoryPackage.path, "pubspec.yaml"));
final File file_pubspec =
File(path.join(directoryPackage.path, "pubspec.yaml"));
if (file_pubspec.existsSync() == false) {
return null;
}
final Map yaml_code = (yaml.loadYaml(file_pubspec.readAsStringSync(), recover: true) as Map);
final Map yaml_code =
(yaml.loadYaml(file_pubspec.readAsStringSync(), recover: true) as Map);
return ArchiveGeneralLib.createArchiveZip(
directory: directoryPackage,
password: password,
outPutFile: File(path.join(directoryOutPut.uri.toFilePath(), "${yaml_code["name"]}-${yaml_code["version"]}")),
outPutFile: File(path.join(directoryOutPut.uri.toFilePath(),
"${yaml_code["name"]}-${yaml_code["version"]}")),
archiveGeneralLibOptions: ArchiveGeneralLibOptions(
fileSystemEntityIgnore: """
.git
Expand All @@ -274,7 +294,8 @@ $fileSystemEntityIgnore
return null;
}

Directory directory_ouput_temp = Directory(path.join(temp_directory.uri.toFilePath(), generateUuid(10)));
Directory directory_ouput_temp =
Directory(path.join(temp_directory.uri.toFilePath(), generateUuid(10)));

if (directory_ouput_temp.existsSync()) {
{
Expand All @@ -283,7 +304,8 @@ $fileSystemEntityIgnore
if (++try_count > 10) {
throw "Error";
}
directory_ouput_temp = Directory(path.join(temp_directory.uri.toFilePath(), generateUuid(10)));
directory_ouput_temp = Directory(
path.join(temp_directory.uri.toFilePath(), generateUuid(10)));
if (directory_ouput_temp.existsSync() == false) {
break;
}
Expand All @@ -296,7 +318,8 @@ $fileSystemEntityIgnore
directoryOutput: directory_ouput_temp,
password: password,
verify: true,
archiveGeneralLibOptions: ArchiveGeneralLibOptions(fileSystemEntityIgnore: """
archiveGeneralLibOptions:
ArchiveGeneralLibOptions(fileSystemEntityIgnore: """
.git
.dart_tool
$fileSystemEntityIgnore
Expand Down Expand Up @@ -344,7 +367,8 @@ $fileSystemEntityIgnore
final res = archiveDirectory(
directoryPackage: directoryPackage,
password: password,
directoryOutPut: Directory(path.join((directoryOutPut ?? Directory.current).path, "temp")),
directoryOutPut: Directory(
path.join((directoryOutPut ?? Directory.current).path, "temp")),
fileSystemEntityIgnore: fileSystemEntityIgnore,
);
if (res == null) {
Expand Down Expand Up @@ -383,7 +407,12 @@ $fileSystemEntityIgnore
return null;
}
for (var i = 0; i < path.split(result.toFilePath()).length; i++) {
File file_pubspec = File(path.join(Directory(path.join(result.toFilePath(), List.generate(i, (index) => "..").join(Dart.pathSeparator))).uri.toFilePath(), "pubspec.yaml"));
File file_pubspec = File(path.join(
Directory(path.join(result.toFilePath(),
List.generate(i, (index) => "..").join(Dart.pathSeparator)))
.uri
.toFilePath(),
"pubspec.yaml"));
if (file_pubspec.existsSync()) {
return file_pubspec.parent;
}
Expand Down
24 changes: 14 additions & 10 deletions lib/dynamic_library/core.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import 'dart:async';

///
/// GeneralLib
abstract class GeneralLibraryDynamicLibraryBaseCore {
///
/// GeneralLib
FutureOr<void> ensureInitialized();
///

/// GeneralLib
bool isCrash();
///

/// GeneralLib
bool isDeviceSupport();
///

/// GeneralLib
FutureOr<void> close();
///

/// GeneralLib
FutureOr<void> dispose();
}
///
abstract class GeneralLibraryDynamicLibraryBase implements GeneralLibraryDynamicLibraryBaseCore {
}

/// GeneralLib
abstract class GeneralLibraryDynamicLibraryBase
implements GeneralLibraryDynamicLibraryBaseCore {}
2 changes: 1 addition & 1 deletion lib/dynamic_library/dynamic_library.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export "core.dart";
export "core.dart";
Loading

0 comments on commit 01a9656

Please sign in to comment.