Skip to content

Commit

Permalink
upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JDDKCN committed Nov 16, 2024
1 parent 690fa9a commit 4cda25b
Show file tree
Hide file tree
Showing 14 changed files with 924 additions and 172 deletions.
28 changes: 27 additions & 1 deletion KCNLanzouDirectLink.Demo/FormMain.Designer.cs

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

86 changes: 78 additions & 8 deletions KCNLanzouDirectLink.Demo/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,102 @@ private async void uiButton1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(uiTextBox1.Text))
{
KUI.Error("请填入分享链接!");
KUI.Error("请填入分享链接!\nPlease enter the shared link!");
return;
}

string? link = null;
(DownloadState state, string? link) result = (DownloadState.Error, null);

if (!string.IsNullOrEmpty(uiTextBox2.Text))
{
// 蓝奏云加密直链获取不稳定,多尝试几次
for (int i = 0; i < 10; i++)
{
link = await KCNLanzouLinkHelper.GetDirectLinkAsync(uiTextBox1.Text, uiTextBox2.Text); // 蓝奏云加密直链获取不稳定,多尝试几次
if (!string.IsNullOrEmpty(link))
result = await KCNLanzouLinkHelper.GetDirectLinkAsync(uiTextBox1.Text, uiTextBox2.Text);
if (result.state == DownloadState.Success)
break;
}
}
else
{
link = await KCNLanzouLinkHelper.GetDirectLinkAsync(uiTextBox1.Text);
result = await KCNLanzouLinkHelper.GetDirectLinkAsync(uiTextBox1.Text);
}

switch (result.state)
{
case DownloadState.Success:
KUI.OK($"直链获取成功!\nDirect link retrieved successfully!\n{result.link}");
break;

case DownloadState.UrlNotProvided:
KUI.Error("请填入分享链接!\nPlease enter the shared link!");
break;

case DownloadState.HtmlContentNotFound:
KUI.Error("无法获取网页内容,请检查链接是否有效!\nUnable to retrieve web content. Please check if the link is valid!");
break;

case DownloadState.PostsignNotFound:
KUI.Error("无法解析加密信息,请检查链接或密钥是否正确!\nUnable to parse encrypted information. Please check if the link or key is correct!");
break;

case DownloadState.IntermediateUrlNotFound:
KUI.Error("中间链接解析失败,请稍后再试!\nFailed to parse the intermediate link. Please try again later!");
break;

case DownloadState.FinalUrlNotFound:
KUI.Error("无法获取最终直链,请检查网络连接!\nUnable to retrieve the final direct link. Please check your network connection!");
break;

default:
KUI.Error("直链获取失败,发生未知错误!\nDirect link retrieval failed. An unknown error occurred!");
break;
}
}

if (link == null)
private async void uiButton2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(uiTextBox1.Text))
{
KUI.Error("直链获取失败!");
KUI.Error("请填入分享链接!\nPlease enter the shared link!");
return;
}

KUI.OK($"直链获取成功!\n{link}");
(DownloadState state, LanzouFileInfo? fileInfo) result;

if (string.IsNullOrEmpty(uiTextBox2.Text))
result = await KCNLanzouLinkHelper.GetFileInfoAsync(uiTextBox1.Text);
else
result = await KCNLanzouLinkHelper.GetFileInfoAsync(uiTextBox1.Text, uiTextBox2.Text);

if (result.state == DownloadState.Success && result.fileInfo != null)
{
LanzouFileInfo fileInfo = result.fileInfo;

string message = $"文件信息解析成功:\n" +
$"File info retrieved successfully:\n" +
$"文件名称\\File Name: {fileInfo.FileName}\n" +
$"文件大小\\File Size: {fileInfo.Size}\n" +
$"上传时间\\Upload Time: {fileInfo.UploadTime}\n" +
$"上传者\\Uploader: {fileInfo.Uploader}\n" +
$"运行平台\\Platform: {fileInfo.Platform}\n" +
$"文件描述\\Description: {fileInfo.Description}";

KUI.OK(message);
}
else
{
switch (result.state)
{
case DownloadState.HtmlContentNotFound:
KUI.Error("无法获取网页内容,请检查链接是否有效!\nUnable to retrieve web content. Please check the link!");
break;

default:
KUI.Error("解析过程中发生错误,请稍后重试!\nAn error occurred during parsing. Please try again later!");
break;
}
}
}
}
}
5 changes: 4 additions & 1 deletion KCNLanzouDirectLink.Demo/KCNLanzouDirectLink.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KCNLanzouDirectLink" Version="1.0.0" />
<PackageReference Include="SunnyUI" Version="3.7.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KCNLanzouDirectLink\KCNLanzouDirectLink.csproj" />
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions KCNLanzouDirectLink.Demo/KUI.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,89 @@
using Sunny.UI;
using System.Runtime.InteropServices;

namespace KCNLanzouDirectLink.Demo
{
internal class KUI
{
[DllImport("user32.dll")]
private static extern IntPtr MonitorFromPoint(Point pt, uint dwFlags);

[DllImport("Shcore.dll")]
private static extern int GetDpiForMonitor(IntPtr hmonitor, int dpiType, out uint dpiX, out uint dpiY);

const int MDT_EFFECTIVE_DPI = 0;

public static Point ScreenCentralLocation(Form form) => GetScreenCentralLocation(form);

private static Point GetScreenCentralLocation(Form form)
{
IntPtr hMonitor = MonitorFromPoint(form.Location, 2);

_ = GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, out uint dpiX, out uint dpiY);

float scaleFactorX = dpiX / 96.0f;
float scaleFactorY = dpiY / 96.0f;

Rectangle workingArea = Screen.FromHandle(form.Handle).WorkingArea;
int centerX = (int)(workingArea.Left + (workingArea.Width / 2) / scaleFactorX);
int centerY = (int)(workingArea.Top + (workingArea.Height / 2) / scaleFactorY);

return new Point(centerX, centerY);
}

public static void Error(string msg)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowErrorDialog("Error", msg);
}

public static void Error(string msg, string title)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowErrorDialog(title, msg);
}

public static void Warning(string msg)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowWarningDialog("Warn", msg);
}

public static void Warning(string msg, string title)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowWarningDialog(title, msg);
}

public static void OK(string msg)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowSuccessDialog("OK", msg);
}

public static void OK(string msg, string title)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowSuccessDialog(title, msg);
}

public static void Info(string msg)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowInfoDialog("Info", msg, UIStyle.Blue);
}

public static void Info(string msg, string title)
{
Sunny.UI.UIForm form = new Sunny.UI.UIForm();
form.Location = ScreenCentralLocation(form);
form.ShowInfoDialog(title, msg, UIStyle.Blue);
}
}
Expand Down
40 changes: 40 additions & 0 deletions KCNLanzouDirectLink/DownloadState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace KCNLanzouDirectLink
{
public enum DownloadState
{
/// <summary>
/// 操作成功完成。
/// </summary>
Success,

/// <summary>
/// 未提供有效的分享链接。
/// </summary>
UrlNotProvided,

/// <summary>
/// 无法获取网页内容。分享链接无效?
/// </summary>
HtmlContentNotFound,

/// <summary>
/// 无法解析加密信息。分享链接无效或密钥错误?
/// </summary>
PostsignNotFound,

/// <summary>
/// 无法解析中间链接。
/// </summary>
IntermediateUrlNotFound,

/// <summary>
/// 无法获取最终的直链地址。
/// </summary>
FinalUrlNotFound,

/// <summary>
/// 未知错误,操作未成功完成。
/// </summary>
Error
}
}
Loading

0 comments on commit 4cda25b

Please sign in to comment.