Skip to content

Commit

Permalink
v1.2.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nobody committed Feb 27, 2020
2 parents 72910ca + 4d5dae6 commit c9e0437
Show file tree
Hide file tree
Showing 37 changed files with 2,373 additions and 390 deletions.
25 changes: 25 additions & 0 deletions Plugins/Luna/Libs/Sys/WinApis.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Runtime.InteropServices;

namespace Luna.Libs.Sys
{
internal static class WinApis
{

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

public static int SetWallpaper(string path)
{
const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;

return SystemParametersInfo(
SPI_SETDESKWALLPAPER,
0,
path,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}

}
}
37 changes: 37 additions & 0 deletions Plugins/Luna/Luna.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Libs\LuaSnippet\LuaSubFuncSnippets.cs" />
<Compile Include="Libs\LuaSnippet\ApiFunctionSnippets.cs" />
<Compile Include="Libs\LuaSnippet\LuaAcm.cs" />
<Compile Include="Libs\Sys\WinApis.cs" />
<Compile Include="Misc\UI.cs" />
<Compile Include="Luna.cs" />
<Compile Include="Models\Apis\Components\Server.cs" />
Expand Down Expand Up @@ -109,6 +110,24 @@
<Compile Include="Views\UserControls\LuaUI.Designer.cs">
<DependentUpon>LuaUI.cs</DependentUpon>
</Compile>
<Compile Include="Views\WinForms\FormInput.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Views\WinForms\FormInput.Designer.cs">
<DependentUpon>FormInput.cs</DependentUpon>
</Compile>
<Compile Include="Views\WinForms\FormChoices.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Views\WinForms\FormChoices.Designer.cs">
<DependentUpon>FormChoices.cs</DependentUpon>
</Compile>
<Compile Include="Views\WinForms\FormChoice.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Views\WinForms\FormChoice.Designer.cs">
<DependentUpon>FormChoice.cs</DependentUpon>
</Compile>
<Compile Include="Views\WinForms\FormMain.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -143,6 +162,24 @@
<EmbeddedResource Include="Views\UserControls\LuaUI.zh-CN.resx">
<DependentUpon>LuaUI.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormInput.resx">
<DependentUpon>FormInput.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormInput.zh-CN.resx">
<DependentUpon>FormInput.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormChoices.resx">
<DependentUpon>FormChoices.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormChoices.zh-CN.resx">
<DependentUpon>FormChoices.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormChoice.resx">
<DependentUpon>FormChoice.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormChoice.zh-CN.resx">
<DependentUpon>FormChoice.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Views\WinForms\FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource>
Expand Down
110 changes: 109 additions & 1 deletion Plugins/Luna/Models/Apis/Components/Misc.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna.Models.Apis.Components
{
Expand All @@ -11,6 +13,7 @@ public sealed class Misc :
VgcApis.Interfaces.Services.IUtilsService vgcUtils;
VgcApis.Interfaces.Services.IShareLinkMgrService vgcSlinkMgr;
VgcApis.Interfaces.Services.IServersService vgcServer;
VgcApis.Interfaces.Services.ISettingsService vgcSettings;

public Misc(
Services.Settings settings,
Expand All @@ -20,6 +23,7 @@ public Misc(
vgcUtils = api.GetUtilsService();
vgcSlinkMgr = api.GetShareLinkMgrService();
vgcServer = api.GetServersService();
vgcSettings = api.GetSettingService();
}

#region ILuaMisc.ImportLinks
Expand Down Expand Up @@ -47,6 +51,67 @@ public int ImportLinks(string links, string mark)

#region ILuaMisc thinggy

public int SetWallpaper(string filename) =>
Libs.Sys.WinApis.SetWallpaper(filename);

public string GetImageResolution(string filename) =>
VgcApis.Misc.Utils.GetImageResolution(filename);

public string PickRandomLine(string filename) =>
VgcApis.Misc.Utils.PickRandomLine(filename);

public string RandomHex(int len) => VgcApis.Misc.Utils.RandomHex(len);

public string NewGuid() => Guid.NewGuid().ToString();

public string GetSubscriptionConfig() => vgcSettings.GetSubscriptionConfig();

public string Input(string title) => Input(title, 3);

public string Input(string title, int lines)
{
using (var form = new Views.WinForms.FormInput(title, lines))
{
var result = form.ShowDialog();
if (result == DialogResult.OK)
{
return form.result;
}
}
return null;
}

public List<int> Choices(string title, NLua.LuaTable choices) =>
Choices(title, choices, false);

public List<int> Choices(string title, NLua.LuaTable choices, bool isShowKey)
{
var list = LuaTableToList(choices, isShowKey);
return GetResultFromChoicesDialog(title, list.ToArray());
}

public List<int> Choices(string title, params string[] choices) =>
GetResultFromChoicesDialog(title, choices);

public int Choice(string title, NLua.LuaTable choices) =>
Choice(title, choices, false);

public int Choice(string title, NLua.LuaTable choices, bool isShowKey)
{
var list = LuaTableToList(choices, isShowKey);
return GetResultFromChoiceDialog(title, list.ToArray());
}

public int Choice(string title, params string[] choices) =>
GetResultFromChoiceDialog(title, choices);

public bool Confirm(string content) =>
VgcApis.Misc.UI.Confirm(content);

public void Alert(string content) =>
MessageBox.Show(content, VgcApis.Misc.Utils.GetAppName());


public long GetTimeoutValue() => VgcApis.Models.Consts.Core.SpeedtestTimeout;

public void RefreshFormMain() => vgcServer.RequireFormMainReload();
Expand Down Expand Up @@ -123,5 +188,48 @@ public void Print(params object[] contents)
GetParent().SendLog(text);
}
#endregion

#region private methods
List<string> LuaTableToList(NLua.LuaTable table, bool isShowKey)
{
var r = new List<string>();
foreach (KeyValuePair<object, object> de in table)
{
var v = de.Value.ToString();
if (isShowKey)
{
v = de.Key.ToString() + @"." + v;
}
r.Add(v);
}
return r;
}

private static List<int> GetResultFromChoicesDialog(string title, string[] choices)
{
using (var form = new Views.WinForms.FormChoices(title, choices))
{
var result = form.ShowDialog();
if (result == DialogResult.OK)
{
return form.results;
}
}
return new List<int>();
}
private static int GetResultFromChoiceDialog(string title, string[] choices)
{
using (var form = new Views.WinForms.FormChoice(title, choices))
{
var result = form.ShowDialog();
if (result == DialogResult.OK)
{
return form.result;
}
}
return -1;
}

#endregion
}
}
21 changes: 17 additions & 4 deletions Plugins/Luna/Models/Apis/Components/Web.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ public List<string> ExtractBase64String(string text) =>
public int GetProxyPort() =>
vgcServers.GetAvailableHttpProxyPort();

public string Fetch(string url) =>
vgcWeb.Fetch(url, -1, -1);
public bool Download(string url, string filename) =>
vgcWeb.Download(url, filename, -1, -1);

public bool Download(string url, string filename, int millSecond) =>
vgcWeb.Download(url, filename, -1, millSecond);

public bool Download(string url, string filename, int proxyPort, int millSecond) =>
vgcWeb.Download(url, filename, proxyPort, millSecond);

public string Fetch(string url) => vgcWeb.Fetch(url, -1, -1);

public string Fetch(string url, int milliSeconds) =>
vgcWeb.Fetch(url, -1, milliSeconds);

public string Fetch(string url, int proxyPort, int milliSeconds) =>
vgcWeb.Fetch(url, proxyPort, milliSeconds);

public int UpdateSubscriptions() =>
vgcSlinkMgr.UpdateSubscriptions(-1);
Expand Down Expand Up @@ -54,8 +68,7 @@ public string PatchHref(string url, string href) =>
public List<string> FindAllHrefs(string text) =>
vgcWeb.FindAllHrefs(text);

public string Fetch(string url, int proxyPort, int milliSeconds) =>
vgcWeb.Fetch(url, proxyPort, milliSeconds);


#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Luna/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Plugins/Luna/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<value>Luna</value>
</data>
<data name="Version" xml:space="preserve">
<value>0.1.3</value>
<comment>do not select first script when editor init</comment>
<value>0.1.5</value>
<comment>accept lua table as param</comment>
</data>
</root>
1 change: 1 addition & 0 deletions Plugins/Luna/Resources/Files/LuaPredefinedFunctions.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import = function () end
print = function(...) Misc:Print(...) end
os.exit = function() print("os.exit() is disabled") end

-- copy from NLua
function Each(o)
Expand Down
81 changes: 81 additions & 0 deletions Plugins/Luna/Views/WinForms/FormChoice.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c9e0437

Please sign in to comment.