Skip to content

Commit 1fb1c0e

Browse files
committed
修复文件修改时间判断错误和网络IO等待时间过长会报错的问题
1 parent 3ad513c commit 1fb1c0e

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

src/main/java/com/github/balloonupdate/mcpatch/client/Work.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,20 @@ boolean run2(Servers server) throws IOException, McpatchBusinessException {
336336
}
337337

338338
// 2.判断文件时间
339-
if ((mtime.toMillis() / 1000 - f.modified) > 5) {
339+
long timeDiff = (mtime.toMillis() / 1000 - f.modified);
340+
341+
// Log.debug(f.path + " : " + timeDiff);
342+
343+
if (timeDiff < 5) {
340344
continue;
341345
}
342346

343347
// 3.对比hash
344348
String hash;
345349

350+
if (window != null)
351+
window.setLabelSecondaryText(PathUtility.getFilename(f.path));
352+
346353
try {
347354
hash = HashUtility.calculateHash(targetPath);
348355
} catch (IOException ex) {
@@ -353,10 +360,17 @@ boolean run2(Servers server) throws IOException, McpatchBusinessException {
353360
continue;
354361
}
355362

363+
// 顺便修复文件修改时间
364+
Files.setLastModifiedTime(targetPath, FileTime.from(f.modified, TimeUnit.SECONDS));
365+
356366
// 执行到这里的就是可以跳过的了
357367
updateFiles.remove(i);
358368
}
359369

370+
// 清空文字
371+
if (window != null)
372+
window.setLabelSecondaryText("");
373+
360374
// 尽可能跳过要创建的目录
361375
for (int i = createFolders.size() - 1; i >= 0; i--) {
362376
String f = createFolders.get(i);

src/main/java/com/github/balloonupdate/mcpatch/client/ui/McPatchWindow.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.balloonupdate.mcpatch.client.ui;
22

3+
import com.github.kasuminova.GUI.SetupSwing;
4+
35
import javax.swing.*;
46
import java.awt.event.WindowAdapter;
57
import java.awt.event.WindowEvent;
@@ -24,13 +26,13 @@ public McPatchWindow(int width, int height) {
2426

2527
window = new JFrame();
2628

27-
label = new JLabel("空标签空标签空标签空标签空标签空标签空标签空标签空标签");
28-
label.setBounds(45, 15, 295, 20);
29+
label = new JLabel("空标签空标签空标签空标签空标签空标签空签空标签空标签空签空标签空标签空标签空标签空标签");
30+
label.setBounds(0, 15, 380, 20);
2931
label.setHorizontalAlignment(JLabel.CENTER);
3032
window.getContentPane().add(label);
3133

32-
labelSecondary = new JLabel("空标签空标签空标签空标签空标签空标签空标签空标签空标签");
33-
labelSecondary.setBounds(45, 40, 295, 20);
34+
labelSecondary = new JLabel("空标签空标签空标签空标签空标空标签空标签空标空标签空标签空标签空标签空标签空标签空标签");
35+
labelSecondary.setBounds(0, 40, 380, 20);
3436
labelSecondary.setHorizontalAlignment(JLabel.CENTER);
3537
window.getContentPane().add(labelSecondary);
3638

@@ -88,6 +90,7 @@ public void destroy() {
8890
// 进度条上的文字
8991
public void setProgressBarText(String value) {
9092
progressBar.setString(value);
93+
progressBar.setToolTipText(value);
9194
}
9295

9396
// 进度条的值
@@ -99,10 +102,12 @@ public void setProgressBarValue(int value) {
99102
// 标签上的文字
100103
public void setLabelText(String value) {
101104
label.setText(value);
105+
label.setToolTipText(value);
102106
}
103107

104108
// 副签上的文字
105109
public void setLabelSecondaryText(String value) {
110+
labelSecondary.setToolTipText(value);
106111
labelSecondary.setText(value);
107112
}
108113

@@ -113,6 +118,7 @@ public interface OnWindowClosing {
113118

114119
// 开发时调试用
115120
public static void main(String[] args) {
121+
SetupSwing.init();
116122
new McPatchWindow().show();
117123
}
118124
}

src/main/java/com/github/balloonupdate/mcpatch/client/utils/BytesUtils.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,21 @@ public static long bytesLeToLong(byte[] bytes) {
142142
* 从流中不断读取数据,直到填满buf或者遇到异常,否则一直读取
143143
*/
144144
public static void readAll(byte[] buf, InputStream input) throws IOException {
145-
int index = 0;
145+
int offset = 0;
146146

147-
while (index < buf.length) {
148-
index += input.read(buf, index, buf.length - index);
147+
while (offset < buf.length) {
148+
int len = buf.length - offset;
149+
150+
RuntimeAssert.isTrue(offset >= 0);
151+
RuntimeAssert.isTrue(len >= 0);
152+
RuntimeAssert.isTrue(len <= buf.length - offset);
153+
154+
int received = input.read(buf, offset, len);
155+
156+
if (received == -1)
157+
throw new IOException("The io reached the end");
158+
159+
offset += received;
149160
}
150161
}
151162

0 commit comments

Comments
 (0)