mirror of
https://onedev.site.tesses.net/crosslang/crosslangdevstudio
synced 2026-02-08 09:15:45 +00:00
New dev build
This commit is contained in:
42
Models/IPackageManager.cs
Normal file
42
Models/IPackageManager.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace CrossLangDevStudio.Models;
|
||||
|
||||
public interface IPackageManager
|
||||
{
|
||||
Task InstallPackageAsync(string name, CrossLangVersion version);
|
||||
string Filter { get; }
|
||||
void UninstallPackage(string name);
|
||||
|
||||
IEnumerable<CrossLangDependency> GetInstalledPackages();
|
||||
}
|
||||
|
||||
public static class PackageManagerExtensions
|
||||
{
|
||||
public static string Summarize(this string txt)
|
||||
{
|
||||
var lines = txt.Replace("\r", "").Split('\n');
|
||||
bool needsthreedots = false;
|
||||
if (lines.Length > 1) needsthreedots = true;
|
||||
if (lines.Length == 0) return "";
|
||||
if (lines[0].Length > 120) { needsthreedots = true; lines[0] = lines[0].Substring(0, 120); }
|
||||
if (needsthreedots) return $"{lines[0]}...";
|
||||
return lines[0];
|
||||
}
|
||||
public static bool IsPackageInstalled(this IPackageManager pm, string name)
|
||||
{
|
||||
foreach (var item in pm.GetInstalledPackages())
|
||||
{
|
||||
if (item.Name == name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static async Task InstallPackageAsync(this IPackageManager pm, CrossLangDependency dep)
|
||||
{
|
||||
await pm.InstallPackageAsync(dep.Name, dep.Version);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user