Skip to content

Commit 03df77e

Browse files
IReboIRebo
authored andcommitted
fix long paths
1 parent 8b95e92 commit 03df77e

4 files changed

Lines changed: 26 additions & 54 deletions

File tree

Form1.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using System.Windows.Forms;
8+
using HtmlAgilityPack;
89
using Windows.ApplicationModel;
910
using Windows.Management.Deployment;
1011
using xtrance.Properties;
@@ -45,6 +46,7 @@ public Form1()
4546
textBoxDirectory.Text = Properties.Settings.Default.FilesPath;
4647
textBoxDirectory.TextChanged += TextBox_TextChanged;
4748

49+
buttonOK.Enabled = true; buttonCancel.Enabled = false;
4850

4951

5052
new Thread(() =>
@@ -85,7 +87,7 @@ public Form1()
8587
{ IsBackground = true }.Start();
8688
}
8789

88-
private string RootPath => textBoxDirectory.Text+ @"\";
90+
private string RootPath => @"\\?\"+textBoxDirectory.Text+ @"\";
8991

9092
private void TextBox_TextChanged(object sender, EventArgs e)
9193
{
@@ -111,6 +113,7 @@ private void buttonOK_Click(object sender, EventArgs e)
111113
string user = textBoxUser.Text;
112114
string pass = textBoxPassword.Text;
113115
int serverId = Int32.Parse(textBoxServer.Text);
116+
buttonOK.Enabled = false; buttonCancel.Enabled = true;
114117

115118
_task = Task.Run(async () =>
116119
{
@@ -171,7 +174,11 @@ private void buttonOK_Click(object sender, EventArgs e)
171174
{
172175
Log(ex.ToString());
173176
}
174-
}, _cancellationToken.Token).ContinueWith(_ => Log("done"));
177+
}, _cancellationToken.Token).ContinueWith(_ => {
178+
Log("done");
179+
buttonOK.Invoke((Action)(() => buttonOK.Enabled = true));
180+
buttonCancel.Invoke((Action)(() => buttonCancel.Enabled = false));
181+
});
175182
}
176183

177184
private void SaveBook(Book book)
@@ -195,6 +202,7 @@ private void SaveMetaBook(MetaBook metaBook)
195202
{
196203
Log("Saving metabook : " + metaBook.ToString());
197204
string path = Sanitize(metaBook.Author) + @"\" + Sanitize(metaBook.Name);
205+
198206
Directory.CreateDirectory(RootPath + path);
199207
if (metaBook.Data != null)
200208
{
@@ -216,7 +224,12 @@ private void labelFrom_Click(object sender, EventArgs e)
216224

217225
private string Sanitize(string input)
218226
{
219-
return String.Join("_", input.Split(Path.GetInvalidFileNameChars())).TrimEnd('.').Trim();
227+
string s = String.Join("_", input.Split(Path.GetInvalidFileNameChars())).TrimEnd('.').Trim();
228+
if (s.Length > 250)
229+
{
230+
s = s.Substring(0, 250);
231+
}
232+
return s;
220233
}
221234

222235
private void buttonUpdate_Click(object sender, EventArgs e)

XtranceAccessor.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Web;
1010
using HtmlAgilityPack;
11+
using static System.Reflection.Metadata.BlobBuilder;
1112

1213
namespace xtrance
1314
{
@@ -17,13 +18,15 @@ public class XtranceAccessor
1718
private Log.LogFunction _logFunction;
1819
private WebClientEx _webClient;
1920
private int _serverId;
21+
private CancellationToken _token;
2022

2123
public XtranceAccessor(string urlbase, Log.LogFunction logFunction, int serverId, CancellationToken token)
2224
{
2325
_webClient = new WebClientEx(logFunction, Encoding.UTF8, 15*1000, token);
2426
_logFunction = logFunction;
2527
_urlbase = urlbase;
2628
_serverId = serverId;
29+
_token= token;
2730
}
2831

2932
public async Task LogingAndGetCookie(string username, string password)
@@ -83,11 +86,15 @@ public async Task<Books> GetLatestBooks(int from, int to)
8386
{
8487
Books bookDict = new Books();
8588
string result = await _webClient.DownloadStringTaskAsync(_urlbase + "/new/?mainpage=nov&nov_view=2");
86-
8789
int bookIndex = 0;
8890

89-
for (int page = from; page <= to; page++)
91+
await Parallel.ForAsync(from, to + 1, new ParallelOptions()
92+
{
93+
MaxDegreeOfParallelism = 5
94+
}, async (page, ct) =>
9095
{
96+
_token.ThrowIfCancellationRequested();
97+
//Thread.Sleep(sleeptime);
9198
result = await _webClient.DownloadStringTaskAsync(_urlbase + "/new/?mainpage=nov&subpage=&id=0&nov_ebk_page=" + page);
9299
HtmlDocument htmlDoc = new HtmlDocument();
93100
htmlDoc.LoadHtml(result);
@@ -108,7 +115,7 @@ public async Task<Books> GetLatestBooks(int from, int to)
108115
bookDict.Add(id, new Book() { Id = id, Index = bookIndex });
109116
}
110117
}
111-
}
118+
});
112119
_logFunction("found " + bookDict.Count + " books...");
113120
return bookDict;
114121
}

app.manifest

Lines changed: 0 additions & 47 deletions
This file was deleted.

xtrance.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<ApplicationIcon>download.ico</ApplicationIcon>
1111
<SignAssembly>True</SignAssembly>
1212
<AssemblyOriginatorKeyFile>xt.snk</AssemblyOriginatorKeyFile>
13-
<ApplicationManifest>app.manifest</ApplicationManifest>
1413
</PropertyGroup>
1514
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
1615
<UseVSHostingProcess>false</UseVSHostingProcess>

0 commit comments

Comments
 (0)