Skip to content

Commit

Permalink
🐛 fix: 修复安装在C盘目录创建失败
Browse files Browse the repository at this point in the history
  • Loading branch information
freeok committed Mar 20, 2024
1 parent b8b58da commit 7b0e0c7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/pcdd/sonovel/core/Crawler.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.pcdd.sonovel.core;

import cn.hutool.core.date.StopWatch;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.setting.dialect.Props;
import com.pcdd.sonovel.model.Chapter;
import com.pcdd.sonovel.model.Book;
import com.pcdd.sonovel.model.Chapter;
import com.pcdd.sonovel.model.SearchResult;
import lombok.SneakyThrows;
import org.jsoup.Jsoup;
Expand All @@ -22,6 +23,8 @@
import java.util.Objects;
import java.util.concurrent.*;

import static org.fusesource.jansi.AnsiRenderer.render;

/**
* @author pcdd
* Created at 2021/6/10 17:03
Expand Down Expand Up @@ -94,9 +97,11 @@ public static double crawl(List<SearchResult> list, int num, int start, int end)

// 小说目录名格式:书名(作者)
bookDir = String.format("%s (%s)", bookName, author);
File dir = new File(SAVE_PATH + File.separator + bookDir);
File dir = FileUtil.mkdir(SAVE_PATH + File.separator + bookDir);
if (!dir.exists()) {
dir.mkdirs();
// C:\Program Files 下创建需要管理员权限
Console.log(render("@|red 下载目录创建失败,若您将软件安装在 C 盘,请以管理员身份重新运行|@"));
return 0;
}

Book book = new BookParser(SOURCE_ID).parse(url);
Expand Down Expand Up @@ -168,7 +173,6 @@ private static void download(Chapter chapter, CountDownLatch latch) {
// Windows 文件名非法字符替换
+ "_" + chapter.getTitle().replaceAll("\\\\|/|:|\\*|\\?|<|>", "")
+ "." + extName;
// TODO fix 下载过快时报错:Exception in thread "pool-2-thread-10" java.io.FileNotFoundException: \so-novel-download\史上最强炼气期(李道然)\3141_第三千一百三十二章 万劫不复 为无敌妙妙琪的两顶皇冠加更(2\2).html (系统找不到指定的路径。)
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(path))) {
fos.write(chapter.getContent().getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
Expand Down

0 comments on commit 7b0e0c7

Please sign in to comment.