Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit e3c071d

Browse files
authored
Merge pull request #86 from OsuSync/fix-bugs
Fix bugs
2 parents 6963194 + 70327fe commit e3c071d

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

Sync/Plugins/PluginManager.cs

+29-3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ internal int LoadPlugins()
355355
allList.Add(it);
356356
}
357357
}
358+
catch (FileNotFoundException e)
359+
{
360+
CheckUnknownDependency(e.FileName.Substring(0, e.FileName.IndexOf(",") - 1));
361+
}
358362
catch (Exception e)
359363
{
360364
//Not up to date
@@ -386,16 +390,25 @@ private List<Type> layerLoader(IList<Type> asmList)
386390
{
387391
try
388392
{
389-
var deps = it.GetCustomAttributes<SyncPluginDependency>();
393+
var hardDeps = it.GetCustomAttributes<SyncPluginDependency>();
390394

391-
foreach (var item in deps)
395+
foreach (var item in hardDeps)
392396
{
393397
var target = allList.Select(p => p.GetCustomAttribute<SyncPluginID>())?.FirstOrDefault(p => p?.GUID == item.GUID);
394398
if (item.Require && target == null) CheckGUIDUpdate(item);
395399
if (item.Version == null) continue;
396400
if (!CompareVersion(item.Version, target.Version)) CheckGUIDUpdate(item);
397401
}
398402

403+
var softDeps = it.GetCustomAttributes<SyncSoftRequirePlugin>();
404+
foreach (var item in softDeps)
405+
{
406+
foreach (var dep in item.RequirePluguins)
407+
{
408+
if (!allList.Any(p => p.Name.Contains(dep) || dep.Contains(p.Name))) CheckUnknownDependency(dep);
409+
}
410+
}
411+
399412
if (LateLoad(it))
400413
{
401414
#if (DEBUG)
@@ -538,6 +551,19 @@ public static bool CompareVersion(string a, string b)
538551
return converter(null);
539552
}
540553

554+
private void CheckUnknownDependency(string name)
555+
{
556+
if (Updater.update.InstallByKeyword(name, false))
557+
{
558+
SyncHost.Instance.ForceRestartSync();
559+
throw new SyncPluginOutdateException($"Need restart application to update {name}");
560+
}
561+
else
562+
{
563+
throw new SyncMissingPluginException($"Can't install dependency plugin: {name}");
564+
}
565+
}
566+
541567
private void CheckGUIDUpdate(SyncPluginDependency item)
542568
{
543569
if (Updater.update.InternalUpdate(item.GUID, true))
@@ -634,4 +660,4 @@ public class SyncPluginDependency : Attribute
634660

635661
public SyncPluginDependency(string guid) => GUID = guid;
636662
}
637-
}
663+
}

Sync/Tools/Builtin/PluginCommand.cs

+19-13
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ private bool AskAgreeUpdate(UpdateData data)
112112
public bool ShouldDownloadUpdate(UpdateData update_data, string current_file_path, bool no_ask)
113113
{
114114
//todo : version compare
115+
if (!File.Exists(current_file_path)) { return true; }
115116

116117
var current_file_hash = MD5HashFile(current_file_path).ToLower();
117118

118-
return ((!File.Exists(current_file_path) || current_file_hash != update_data.latestHash) && AskAgreeUpdate(update_data));
119+
return (current_file_hash != update_data.latestHash) && AskAgreeUpdate(update_data);
119120
}
120121

121122
internal bool InternalUpdate(string plugin_guid, bool no_ask)
@@ -144,7 +145,7 @@ internal bool InternalUpdate(string plugin_guid, bool no_ask)
144145
}
145146
catch (Exception e)
146147
{
147-
IO.CurrentIO.WriteColor(string.Format(LANG_UPDATE_ERROR, e.TargetSite.Name, e.Message), ConsoleColor.Red);
148+
IO.CurrentIO.WriteColor(string.Format(LANG_UPDATE_ERROR, e.TargetSite.Name, e.Message), ConsoleColor.Yellow);
148149
}
149150

150151
return false;
@@ -211,6 +212,20 @@ private bool Search(string keyword)
211212
return false;
212213
}
213214

215+
internal bool InstallByKeyword(string keyword, bool requireRestart = true)
216+
{
217+
if (Serializer<UpdateData[]>($"http://sync.mcbaka.com/api/Update/search/{keyword}") is UpdateData[] datas)
218+
{
219+
if (datas.Length == 0 || InternalUpdate(datas[0].guid, true))
220+
{
221+
if (requireRestart) RequireRestart(LANG_INSTALL_DONE);
222+
return true;
223+
}
224+
else return false;
225+
}
226+
return false;
227+
}
228+
214229
private bool Install(string guid)
215230
{
216231
if (InternalUpdate(guid, true))
@@ -220,16 +235,7 @@ private bool Install(string guid)
220235
}
221236
else
222237
{
223-
if (Serializer<UpdateData[]>($"http://sync.mcbaka.com/api/Update/search/{guid}") is UpdateData[] datas)
224-
{
225-
if (datas.Length == 0 || InternalUpdate(datas[0].guid, true))
226-
{
227-
RequireRestart(LANG_INSTALL_DONE);
228-
return true;
229-
}
230-
else return false;
231-
}
232-
return false;
238+
return InstallByKeyword(guid);
233239
}
234240
}
235241

@@ -443,4 +449,4 @@ private bool DownloadSingleFile(string dlUrl, string path, string name)
443449
}
444450
}
445451
}
446-
}
452+
}

0 commit comments

Comments
 (0)