Skip to content

Commit 6cc60e4

Browse files
committed
using LeoConsole's built-in log capabilities
1 parent 5a8b8ba commit 6cc60e4

File tree

8 files changed

+77
-104
lines changed

8 files changed

+77
-104
lines changed

Apkg/integrity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using ILeoConsole.Core;
12
using System.Linq;
23

34
namespace LeoConsole_apkg {
@@ -17,7 +18,7 @@ public static string CheckPkgConflicts(string[] files, string savePath) {
1718

1819
// Register() {{{
1920
public static void Register(string p, string pVersion, string[] f, string savePath) {
20-
ApkgOutput.MessageSuc0($"registering package {p} v{pVersion}");
21+
LConsole.MessageSuc0($"registering package {p} v{pVersion}");
2122
string baseDir = Path.Join(savePath, "var", "apkg", "installed", p);
2223
Directory.CreateDirectory(baseDir);
2324
File.WriteAllLines(Path.Join(baseDir, "files"), f);

Apkg/repository.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public ApkgRepository(string sp, string v) {
2121
Index = Enumerable.Empty<RepoPackage>().ToList();
2222

2323
if (!Directory.Exists(ReposFolder)) {
24-
ApkgOutput.MessageWarn1("could not find repo cache, package list cannot be loaded");
25-
ApkgOutput.MessageWarn1("please run 'apkg reload'");
24+
LConsole.MessageWarn1("could not find repo cache, package list cannot be loaded");
25+
LConsole.MessageWarn1("please run 'apkg reload'");
2626
return;
2727
}
2828

@@ -78,7 +78,7 @@ public IList<string> AvailablePlugins() {
7878
public void Reload(ConfigRepo[] repos) {
7979
IList<RepoPackage> newIndex = Enumerable.Empty<RepoPackage>().ToList();
8080
foreach (ConfigRepo repo in repos) {
81-
ApkgOutput.MessageSuc0("loading " + repo.name);
81+
LConsole.MessageSuc0("loading " + repo.name);
8282
string tempFile = Path.Join(DownloadPath, repo.name + ".json");
8383
if (!ApkgUtils.DownloadFile(repo.url, tempFile)) {
8484
throw new Exception("error downloading " + repo.name);
@@ -106,48 +106,48 @@ private string ExtractLcp(string path) {
106106
}
107107
Directory.CreateDirectory(extractPath);
108108
// extract package archive
109-
ApkgOutput.MessageSuc0("extracting package");
109+
LConsole.MessageSuc0("extracting package");
110110
ZipFile.ExtractToDirectory(path, extractPath);
111111
return extractPath;
112112
} // }}}
113113

114114
// InstallFiles() {{{
115115
private void InstallFiles(string[] files, string packageDir) {
116116
foreach (string file in files) {
117-
ApkgOutput.MessageSuc1("copying " + file);
117+
LConsole.MessageSuc1("copying " + file);
118118
Directory.CreateDirectory(Directory.GetParent(Path.Join(SavePath, file)).FullName);
119119
// copy file
120120
File.Copy(Path.Join(packageDir, file), Path.Join(SavePath, file), true);
121121
if (
122122
(file.StartsWith("share/scripts") || file.StartsWith("share/go-plugin"))
123123
&& ApkgUtils.GetRunningOS() == "lnx64"
124124
) {
125-
ApkgOutput.MessageSuc1($"marking {file} as executable");
125+
LConsole.MessageSuc1($"marking {file} as executable");
126126
if (!ApkgUtils.RunProcess("chmod", "+x " + Path.Join(SavePath, file), SavePath)) {
127-
ApkgOutput.MessageWarn1($"cannot mark {file} as executable");
127+
LConsole.MessageWarn1($"cannot mark {file} as executable");
128128
}
129129
}
130130
}
131131
} // }}}
132132

133133
// InstallLcpkg() {{{
134134
public void InstallLcpkg(string archiveFile) {
135-
ApkgOutput.MessageSuc0("installing package");
136-
ApkgOutput.MessageSuc1("preparing to extract package");
135+
LConsole.MessageSuc0("installing package");
136+
LConsole.MessageSuc1("preparing to extract package");
137137

138138
string tempFolder = "";
139139
try {
140140
tempFolder = ExtractLcp(archiveFile);
141141
} catch (Exception e) {
142-
ApkgOutput.MessageErr0($"cannot extract lcp archive: {e.Message}");
142+
LConsole.MessageErr0($"cannot extract lcp archive: {e.Message}");
143143
return;
144144
}
145145

146-
ApkgOutput.MessageSuc0("checking package compatibility");
146+
LConsole.MessageSuc0("checking package compatibility");
147147
PkgArchiveManifest manifest = FileUtils.ReadManifest(tempFolder);
148148

149149
if (!Array.Exists(manifest.compatibleVersions, e => e == LeoConsoleVersion)) {
150-
ApkgOutput.MessageErr1("your LeoConsole version is incompatible with this plugin");
150+
LConsole.MessageErr1("your LeoConsole version is incompatible with this plugin");
151151
return;
152152
}
153153

@@ -157,7 +157,7 @@ public void InstallLcpkg(string archiveFile) {
157157
try {
158158
url = GetUrlFor(pack);
159159
} catch (Exception e) {
160-
ApkgOutput.MessageErr1("cannot find a dependency");
160+
LConsole.MessageErr1("cannot find a dependency");
161161
return;
162162
}
163163
string dlPath = Path.Join(DownloadPath, $"{pack}.lcp");
@@ -171,46 +171,46 @@ public void InstallLcpkg(string archiveFile) {
171171
string conflictsWith = ApkgIntegrity.CheckPkgConflicts(manifest.files, SavePath);
172172
if (conflictsWith != "") {
173173
if (conflictsWith != manifest.packageName) {
174-
ApkgOutput.MessageErr0($"{manifest.packageName} conflicts with {conflictsWith}, aborting install");
174+
LConsole.MessageErr0($"{manifest.packageName} conflicts with {conflictsWith}, aborting install");
175175
return;
176176
}
177177
// conflicting with itself ask about reinstalling {{{
178178
string installedVersion = File.ReadAllText(Path.Join(ConfigDir, "installed", manifest.packageName, "version")).Trim();
179179
if (installedVersion == manifest.packageVersion) {
180180
if (!LConsole.YesNoDialog("reinstall same package version?", true)) {
181-
ApkgOutput.MessageErr1("installation aborted");
181+
LConsole.MessageErr1("installation aborted");
182182
return;
183183
}
184184
}
185185
if (ApkgUtils.VersionGreater(installedVersion, manifest.packageVersion)) {
186186
if (!LConsole.YesNoDialog($"downgrade package ({installedVersion}->{manifest.packageVersion})?", false)) {
187-
ApkgOutput.MessageErr1("installation aborted");
187+
LConsole.MessageErr1("installation aborted");
188188
return;
189189
}
190190
} // }}}
191191
RemovePackage(manifest.packageName);
192192
} // }}}
193193

194-
ApkgOutput.MessageSuc0($"installing files for {manifest.project.maintainer}/{manifest.packageName}");
194+
LConsole.MessageSuc0($"installing files for {manifest.project.maintainer}/{manifest.packageName}");
195195
InstallFiles(manifest.files, tempFolder);
196196

197197
ApkgIntegrity.Register(
198198
manifest.packageName, manifest.packageVersion, manifest.files, SavePath
199199
);
200-
ApkgOutput.MessageSuc0("successfully installed " + manifest.packageName);
200+
LConsole.MessageSuc0("successfully installed " + manifest.packageName);
201201
} // }}}
202202

203203
// RemovePackage() {{{
204204
public void RemovePackage(string p) {
205-
ApkgOutput.MessageSuc0("removing " + p);
205+
LConsole.MessageSuc0("removing " + p);
206206
if (!Directory.Exists(Path.Join(ConfigDir, "installed", p))) {
207-
ApkgOutput.MessageErr0($"{p} is not installed");
207+
LConsole.MessageErr0($"{p} is not installed");
208208
return;
209209
}
210210
try {
211211
FileUtils.DeleteFiles(File.ReadLines(Path.Join(ConfigDir, "installed", p, "files")).ToArray(), SavePath);
212212
} catch (Exception e) {
213-
ApkgOutput.MessageErr0("removing package failed: " + e.Message);
213+
LConsole.MessageErr0("removing package failed: " + e.Message);
214214
return;
215215
}
216216
ApkgIntegrity.Unregister(p, SavePath);

Utils/fileutils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using ILeoConsole.Core;
12
using System.Text.Json;
23

34
namespace LeoConsole_apkg {
@@ -18,7 +19,7 @@ public static void DeleteParentDirs(string file, string savePath) {
1819
public static void DeleteFiles(string[] files, string savePath) {
1920
foreach (string f in files) {
2021
string path = Path.Join(savePath, f);
21-
ApkgOutput.MessageSuc1("deleting " + path);
22+
LConsole.MessageSuc1("deleting " + path);
2223
File.Delete(path);
2324
FileUtils.DeleteParentDirs(path, savePath);
2425
}

Utils/output.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

Utils/utils.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using ILeoConsole.Core;
12
using System.Diagnostics;
23
using System.IO;
34
using System.Net;
@@ -48,24 +49,24 @@ public static bool RunProcess(string name, string args, string pwd) {
4849
p.Start();
4950
p.WaitForExit();
5051
if (p.ExitCode != 0) {
51-
ApkgOutput.MessageErr1($"{name} returned an error");
52+
LConsole.MessageErr1($"{name} returned an error");
5253
return false;
5354
}
5455
} catch (Exception e) {
55-
ApkgOutput.MessageErr1($"cannot run {name}: {e.Message}");
56+
LConsole.MessageErr1($"cannot run {name}: {e.Message}");
5657
return false;
5758
}
5859
return true;
5960
} // }}}
6061

6162
// DownloadFile() {{{
6263
public static bool DownloadFile(string url, string location) {
63-
ApkgOutput.MessageSuc1($"downloading {url} to {location}...");
64+
LConsole.MessageSuc1($"downloading {url} to {location}...");
6465
try {
6566
WebClient webClient = new WebClient();
6667
webClient.DownloadFile(url, location);
6768
} catch (Exception e) {
68-
ApkgOutput.MessageErr1("cannot download: " + e.Message);
69+
LConsole.MessageErr1("cannot download: " + e.Message);
6970
return false;
7071
}
7172
return true;

0 commit comments

Comments
 (0)