Imports System.Text.RegularExpressions
Imports System.Net
Public Class Form1
Dim 路径 As String
Dim 地址名 As String
Dim 分享链接 As String
Dim 直链地址 As String
Function 解析路径()
Dim pattern As String = "^https:\/\/([\.\w-]+)\/.*$"
Dim regex As New Regex(pattern)
Dim match As Match = regex.Match(TextBox1.Text)
Return match.Groups(1).Value
End Function
Function 解析地址名()
Dim pattern As String = "\/g\/personal\/(\w+)\/"
Dim regex As New Regex(pattern)
Dim match As Match = regex.Match(TextBox1.Text)
Return match.Groups(1).Value
End Function
Function 解析分享链接()
Dim pattern As String = "\/([^\/\?\:]+)\?"
Dim regex As New Regex(pattern)
Dim match As Match = regex.Match(TextBox1.Text)
Return match.Groups(1).Value
End Function
Function 判断是否文件夹()
Dim pattern As String = "\/:([^\/:]+):\/"
Dim regex As New Regex(pattern)
Dim match As Match = regex.Match(TextBox1.Text)
Return match.Groups(1).Value
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '解析
'先清空之前的数据,避免BUG
路径 = ""
地址名 = ""
分享链接 = ""
直链地址 = ""
If 判断是否文件夹() = "f" Then
TextBox2.Text = "当前分享的链接为文件夹,无法解析。"
Else
路径 = 解析路径()
地址名 = 解析地址名()
分享链接 = 解析分享链接()
'组合数据
直链地址 = "https://" & 路径 & "/personal/" & 地址名 & "/_layouts/52/download.aspx?share=" & 分享链接
TextBox2.Text = 直链地址
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click '清空两个输入框
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click '打开生成的解析按钮
If TextBox2.Text = "" Then
MsgBox("未生成解析的地址,请生成解析后重试。")
Else
Dim url As String = TextBox2.Text
'使用Process.Start方法打开默认浏览器并跳转到指定URL
Process.Start(url)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class