Skip to content

Commit

Permalink
A BIG UPDATA
Browse files Browse the repository at this point in the history
perfect the setwindow
  • Loading branch information
GeofferyGeng committed Aug 14, 2018
1 parent fa6c80a commit 1d0af08
Show file tree
Hide file tree
Showing 71 changed files with 102,982 additions and 43 deletions.
Binary file modified .vs/aria2c_v2/DesignTimeBuild/.dtbcache
Binary file not shown.
Binary file modified .vs/aria2c_v2/v15/.suo
Binary file not shown.
Binary file modified .vs/aria2c_v2/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/aria2c_v2/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/aria2c_v2/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
12 changes: 8 additions & 4 deletions aria2c_v2/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="aria2c_v2.MainWindow" WindowStyle="None" BorderThickness="0" ResizeMode="NoResize"
<Window x:Class="aria2c_v2.MainWindow" WindowStyle="None" BorderThickness="1" BorderBrush="Gray" ResizeMode="NoResize"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -9,7 +9,7 @@
Title="MainWindow" Height="500" Width="900" MaxHeight="600" MaxWidth="900">
<Grid>
<Grid>
<WrapPanel Height="32" MouseMove="TitleBar_MouseMove" Background="#CCCCCC" DockPanel.Dock="Top" Margin="0,0,0,468" >
<WrapPanel Height="32" MouseMove="TitleBar_MouseMove" Background="#CCCCCC" DockPanel.Dock="Top" Margin="0,0,0,465.6" >
<TextBlock x:Name="txtTitle" Margin="1,0,0,0" Padding="5,3,2,3" Text=" Aria2"
HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" FontFamily="微软雅黑" Foreground="White"/>
</WrapPanel>
Expand Down Expand Up @@ -89,8 +89,12 @@
</Style>
</Button.Style>
</Button>
<!-- saved from url=(0014)about:internet -->
<WebBrowser x:Name="web" HorizontalAlignment="Left" Height="468" Margin="0,32,0,0" VerticalAlignment="Top" Width="900"/>
<!--
<MediaElement Width="800" Height="400" Source="pic\l.gif"/>
-->

<WebBrowser x:Name="web" HorizontalAlignment="Left" Height="468" Margin="0,32,-0.4,-2.4" VerticalAlignment="Top" Width="898"/>


</Grid>
Expand Down
158 changes: 151 additions & 7 deletions aria2c_v2/MainWindow.xaml.cs

Large diffs are not rendered by default.

359 changes: 355 additions & 4 deletions aria2c_v2/Setwindow.xaml

Large diffs are not rendered by default.

223 changes: 220 additions & 3 deletions aria2c_v2/Setwindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using System;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Newtonsoft.Json.Linq;
using System.Diagnostics;

namespace aria2c_v2
{
Expand All @@ -19,13 +24,211 @@ namespace aria2c_v2
/// </summary>
public partial class Setwindow : Window
{
public string config_to_be_wrriten { get; set; }
public string config { get; set; }
public Setwindow()
{
InitializeComponent();
loadset();

}


//load set from config
public void loadset()
{
string path = System.Environment.CurrentDirectory;
path = System.IO.Path.Combine(path, "aria2c.conf");
//MessageBox.Show(path);
FileInfo fi = new FileInfo(path);
long len = fi.Length;
FileStream fs = new FileStream(path, FileMode.Open);
byte[] buffer = new byte[len];
fs.Read(buffer, 0, (int)len);
fs.Close();
string raw = Encoding.ASCII.GetString(buffer);// Encoding.Unicode.GetString(buffer);

var obj = JObject.Parse(raw);
t_split.Text = obj["split"].ToString();
t_dir.Text = obj["dir"].ToString();
t_diskcache.Text = obj["disk-cache"].ToString();
t_maxconcurrentdownloads.Text = obj["max-concurrent-downloads"].ToString();
t_minsplitsize.Text = obj["min-split-size"].ToString();
t_maxdownloadlimit.Text = obj["max-download-limit"].ToString();
t_fileallocation.Text = obj["file-allocation"].ToString();
t_continue.Text = obj["continue"].ToString();
t_followtorrent.Text = obj["follow-torrent"].ToString();
t_btmaxpeers.Text = obj["bt-max-peers"].ToString();
t_enabledht.Text = obj["enable-dht"].ToString();
t_seedratio.Text = obj["seed-ratio"].ToString();

}

public void changeconfig()
{
MainWindow m = new MainWindow();
m.split = t_split.Text;
m.dir = t_dir.Text;
m.diskcache = t_diskcache.Text;
m.maxconcurrentdownloads = t_maxconcurrentdownloads.Text;
m.maxdownloadlimit = t_maxdownloadlimit.Text;
m.minsplitsize = t_minsplitsize.Text;
m.file_allocation = t_fileallocation.Text;
m.followtorrent = t_followtorrent.Text;
m.enabledht = t_enabledht.Text;
m.seedratio = t_seedratio.Text;
m.continue_ = t_continue.Text;
m.btmaxpeers = t_btmaxpeers.Text;


config_to_be_wrriten = "{dir:" + m.dir + ",split:" + m.split + ",disk-cache:" + m.diskcache + ",max-concurrent-downloads:" +
m.maxconcurrentdownloads + ",max-download-limit:" + m.maxdownloadlimit + ",min-split-size:" + m.minsplitsize + ",file-allocation:" +
m.file_allocation + ",follow-torrent:" + m.followtorrent + ",enable-dht:" + m.enabledht + ",seed-ratio:" +
m.seedratio + ",continue:" + m.continue_ + ",bt-max-peers:" + m.btmaxpeers + "}";

config_to_be_wrriten = config_to_be_wrriten.Replace("{","{\"");
config_to_be_wrriten = config_to_be_wrriten.Replace("}", "\"}");
config_to_be_wrriten = config_to_be_wrriten.Replace(":", "\":\"");
config_to_be_wrriten = config_to_be_wrriten.Replace(",", "\",\"");
config_to_be_wrriten = config_to_be_wrriten.Replace("\":\"\\", ":\\\\");

loggingconfig(config_to_be_wrriten);

config = " --dir=" + m.dir + " " + "--split=" + m.split + " " + "--disk-cache=" + m.diskcache + " " + "--max-concurrent-downloads=" + m.maxconcurrentdownloads +
" " + "--min-split-size=" + m.minsplitsize + " " + "--max-download-limit=" + m.maxdownloadlimit + " " + "--file-allocation=" + m.file_allocation +
" " + "--continue=" + m.continue_ + " " + "--follow-torrent=" + m.followtorrent + " " + "--bt-max-peers=" + m.btmaxpeers + " " + "--enable-dht=" + m.enabledht +
" " + "--seed-ratio=" + m.seedratio; //+ " " + "--bt-tracker=" + bttracker;


kill_one_aria2();

}


public void loggingconfig(string text)
{

try
{
string path = System.Environment.CurrentDirectory;

if (File.Exists("aria2c.conf"))
{
File.Delete("aria2c.conf");
File.Create("aria2c.conf").Close();
}

using (
var outfile =
new StreamWriter(System.IO.Path.Combine(path, "aria2c.conf"), true)
)
{
outfile.WriteLine(text);
}

}
catch (Exception)
{
// ignored
}

}



public void startaria2()
{

string aria2path = System.IO.Path.Combine(System.Environment.CurrentDirectory, @"aria2c.exe");
string config_default = "--enable-rpc --console-log-level=error --rpc-allow-origin-all=true --rpc-listen-port=6800 --save-session-interval=60 --input-file=aria2.session --save-session=aria2.session";

if (!File.Exists("aria2c.session"))
{
File.Create("aria2c.session").Close();
}
if (File.Exists(aria2path))
{
Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = aria2path;
p.StartInfo.Arguments = config_default + config;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
}
}
//close process aria2
public void kill_one_aria2()
{
int a = 1;
Process[] myProgress;
myProgress = Process.GetProcesses();          //获取当前启动的所有进程
foreach (Process p in myProgress)
{
if (p.ProcessName == "aria2c")          //通过进程名来寻找
{
a = a - 1;
if (a == 0)
{
p.Kill();
return;
}

}
}
}
public void killaria2()
{

Process[] myProgress;
myProgress = Process.GetProcesses();          //获取当前启动的所有进程
foreach (Process p in myProgress)
{
if (p.ProcessName == "aria2c")          //通过进程名来寻找
{
p.Kill();
break;
}
}
}


private void set_ok_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult r1 = System.Windows.MessageBox.Show("是否立即应用新的设置?立即应用设置可能导致当前正在进行的任务暂停,重新开始。点否将在下一次启动时应用。", "立即生效?",MessageBoxButton.YesNoCancel);

if (r1 == System.Windows.MessageBoxResult.Yes)
{
System.Windows.MessageBox.Show("Aria2c配置已更新!","Aria2c配置",System.Windows.MessageBoxButton.OK);
changeconfig();
this.Close();

}
else if (r1 == System.Windows.MessageBoxResult.No)
{
System.Windows.MessageBox.Show("Aria2c配置将于下次启动时更新!", "Aria2c配置", System.Windows.MessageBoxButton.OK);
changeconfig();
this.Close();

}
else
{
//reture;
}

}

private void set_cancel_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult r2 = System.Windows.MessageBox.Show("离开并放弃所有更改?","关闭设置",MessageBoxButton.OKCancel);
if (r2 == MessageBoxResult.OK)
{
this.Close();
}
else
{
//reture
}
}



Expand All @@ -42,7 +245,7 @@ public Setwindow()
/// <summary>
/// 窗口移动事件
/// </summary>
private void TitleBar_MouseMove(object sender, MouseEventArgs e)
private void TitleBar_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Expand All @@ -62,7 +265,21 @@ private void btn_min_Click(object sender, RoutedEventArgs e)
private void btn_close_Click(object sender, RoutedEventArgs e)
{
this.Close();


}

private void file_path_Click(object sender, RoutedEventArgs e)
{

FolderBrowserDialog m_Dialog = new FolderBrowserDialog();
DialogResult result = m_Dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string m_Dir = m_Dialog.SelectedPath.Trim();
t_dir.Text = m_Dir;
t_dir.ToolTip = m_Dir;
}

}
Expand Down
14 changes: 14 additions & 0 deletions aria2c_v2/aria2c_v2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -99,9 +104,11 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="UIAutomationProvider" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down Expand Up @@ -154,6 +161,7 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="aria2c_v2_TemporaryKey.pfx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -189,5 +197,11 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="conf.xml" />
</ItemGroup>
<ItemGroup>
<Resource Include="pic\l.gif" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file added aria2c_v2/bin/Debug/Newtonsoft.Json.dll
Binary file not shown.
Loading

0 comments on commit 1d0af08

Please sign in to comment.