Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
测试版本,加入了直接从分享页面下载的功能,具体请看更新日志
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Nov 30, 2016
1 parent 5119213 commit 7acc125
Show file tree
Hide file tree
Showing 27 changed files with 1,065 additions and 152 deletions.
46 changes: 41 additions & 5 deletions BaiduPanDownload/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\\" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd'.log'" />
<staticLogFileName value="false" />
<param name="MaxSizeRollBackups" value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date] [Thread:%thread] [%level] [%logger] %message%newline" />
</layout>
</appender>
<root>
<level value="ERROR" />
<level value="INFO" />
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>

</configuration>
34 changes: 31 additions & 3 deletions BaiduPanDownload/BaiduPanDownload.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -74,11 +76,16 @@
<OutputPath>bin\x86\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.5\lib\net40-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -92,10 +99,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Data\Operation\CopyInfo.cs" />
<Compile Include="Data\ListItem.cs" />
<Compile Include="Data\DiskFileInfo.cs" />
<Compile Include="Data\Operation\Delete.cs" />
<Compile Include="Data\Operation\ShareKey.cs" />
<Compile Include="Data\SpaceInfo.cs" />
<Compile Include="Data\Operation\SuperFile.cs" />
<Compile Include="Forms\AddDownload.cs">
Expand All @@ -104,6 +109,12 @@
<Compile Include="Forms\AddDownload.Designer.cs">
<DependentUpon>AddDownload.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Download.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Download.Designer.cs">
<DependentUpon>Download.cs</DependentUpon>
</Compile>
<Compile Include="Forms\InPutCode.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -128,10 +139,18 @@
<Compile Include="Forms\NewDir.Designer.cs">
<DependentUpon>NewDir.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Setting.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Setting.Designer.cs">
<DependentUpon>Setting.cs</DependentUpon>
</Compile>
<Compile Include="HttpTool\Download\DownloadInfo.cs" />
<Compile Include="HttpTool\Download\DownloadThread.cs" />
<Compile Include="HttpTool\Download\HttpDownload.cs" />
<Compile Include="HttpTool\WebDownload.cs" />
<Compile Include="Managers\CopyManager.cs" />
<Compile Include="Managers\SQLManager.cs" />
<Compile Include="Managers\TaskManager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -140,11 +159,15 @@
<Compile Include="Util\FileTool\Config.cs" />
<Compile Include="HttpTool\WebTool.cs" />
<Compile Include="Util\FileTool\HashTool.cs" />
<Compile Include="Util\FileTool\LogTool.cs" />
<Compile Include="Util\ShowCommands.cs" />
<Compile Include="Util\TaskState.cs" />
<EmbeddedResource Include="Forms\AddDownload.resx">
<DependentUpon>AddDownload.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Download.resx">
<DependentUpon>Download.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\InPutCode.resx">
<DependentUpon>InPutCode.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -157,6 +180,9 @@
<EmbeddedResource Include="Forms\NewDir.resx">
<DependentUpon>NewDir.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Setting.resx">
<DependentUpon>Setting.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -201,7 +227,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="HttpTool\Upload\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion BaiduPanDownload/Data/DiskFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DiskFileInfo[] getFileList()
{
if (isdir != 1)
{
return null;
return new DiskFileInfo[] { this };
}
ArrayList FileList = new ArrayList();
JObject jobj = JObject.Parse(WebTool.GetHtml($"https://pcs.baidu.com/rest/2.0/pcs/file?method=list&access_token={Program.config.Access_Token}&path="+ Uri.EscapeDataString(path)));
Expand Down
17 changes: 0 additions & 17 deletions BaiduPanDownload/Data/ListItem.cs

This file was deleted.

17 changes: 0 additions & 17 deletions BaiduPanDownload/Data/Operation/ShareKey.cs

This file was deleted.

51 changes: 49 additions & 2 deletions BaiduPanDownload/Forms/AddDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BaiduPanDownload.Data;
using BaiduPanDownload.HttpTool;
using BaiduPanDownload.Util;
using BaiduPanDownload.Util.FileTool;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
Expand All @@ -11,8 +12,11 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Windows.Forms;

namespace BaiduPanDownload.Forms
Expand All @@ -21,21 +25,64 @@ public partial class AddDownload : Form
{
Main main;
BaiduPanDownload.Data.DiskFileInfo info;
public AddDownload(Main main, BaiduPanDownload.Data.DiskFileInfo info)
bool URLMode = false;
string Url = string.Empty;
public AddDownload(Main main, BaiduPanDownload.Data.DiskFileInfo info,bool URLMode=false,string Url="")
{
InitializeComponent();
this.main = main;
this.info = info;
this.URLMode = URLMode;
this.Url = Url;
}

private void AddDownload_Load(object sender, EventArgs e)
{
textBox1.Text = Program.config.DownloadPath;
this.TopMost = true;
if (URLMode)
{
FileName_Lab.Text = "文件名: 获取中";
FileSize_Lab.Text = "文件大小: 获取中";
DriveSpace_Lab.Text = textBox1.Text.Substring(0, 1) + "盘剩余空间: " + ((getSizeGB(GetFreeSpace(textBox1.Text.Substring(0, 1)))) < 1 ? getSizeMB(GetFreeSpace(textBox1.Text.Substring(0, 1))) + " MB" : getSizeGB(GetFreeSpace(textBox1.Text.Substring(0, 1))) + " GB");
button2.Enabled = false;
button2.Text = "请等待..";
new Thread(() =>
{
try
{
HttpWebRequest Request = WebRequest.Create(Url) as HttpWebRequest;
//Request.UserAgent = "netdisk;5.3.4.5;PC;PC-Windows;5.1.2600;WindowsBaiduYunGuanJia";
Request.Timeout = 5000;
Cookie ck = new Cookie("BDUSS", "gxQVpVd0FOSWl3LUxHWFhwSmo1bERSTFltTmNMcUloLUJlUDdsV0wzMmRLbHRZSVFBQUFBJCQAAAAAAAAAAAEAAAABq9szNDg5N2Y5cwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ2dM1idnTNYdz");
ck.Domain = ".baidu.com";
Request.CookieContainer = new CookieContainer();
Request.CookieContainer.Add(ck);
ck=new Cookie("pcsett", "1480509997-a88b34ea2ae3d43000459f113c929536");
ck.Domain = ".baidu.com";
Request.CookieContainer.Add(ck);
Request.Referer = "http://pan.baidu.com/disk/home";
HttpWebResponse Response = Request.GetResponse() as HttpWebResponse;
string name = Response.Headers["Content-Disposition"];
name = HttpUtility.UrlDecode(name);
long length = Response.ContentLength;
Regex rg = new Regex("(?<=(" + "=\"" + "))[.\\s\\S]*?(?=(" + "\"" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
FileName_Lab.Text = "文件名: " + rg.Match(name).Value;
FileSize_Lab.Text = "文件大小: " + (getSizeGB(length) < 1 ? getSizeMB(length) + " MB" : getSizeGB(length) + " GB");
button2.Enabled = true;
button2.Text = "添加下载";
}
catch(Exception ex)
{
LogTool.WriteLogError(typeof(AddDownload),"获取文件信息失败:"+Url,ex);
}
}).Start();
return;
}
FileName_Lab.Text = "文件名: "+info.getName();
FileSize_Lab.Text = "文件大小: " + ((info.isdir==1)?"未知":(getSizeGB(info.size)<1?getSizeMB(info.size)+" MB":getSizeGB(info.size)+" GB"));
DriveSpace_Lab.Text = textBox1.Text.Substring(0, 1) + "盘剩余空间: " + ((getSizeGB(GetFreeSpace(textBox1.Text.Substring(0, 1))))<1?getSizeMB(GetFreeSpace(textBox1.Text.Substring(0, 1)))+" MB":getSizeGB(GetFreeSpace(textBox1.Text.Substring(0, 1)))+" GB");
}

float getSizeGB(long byt)
{
return (float)byt / 1024 / 1024 / 1024;
Expand Down
Loading

0 comments on commit 7acc125

Please sign in to comment.