Skip to content

Commit 7211b4f

Browse files
authored
Merge pull request #20 from alexanderwe/feature/win
Feature/win
2 parents 4b97cc2 + 0c93840 commit 7211b4f

19 files changed

+1826
-1835
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
{
2+
"editor.formatOnSave": false
23
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ checksum-validator is a small convenient Electron application, which can quickly
1111
_Supported platforms_
1212

1313
* MacOS (tested under V. 10.13 (High Sierra))
14+
* Windows (tested under Win 10 Pro, Version 1803)
15+
* Update process is not tested yet, if you see some trouble with future releases please file an issue :)
1416

1517
Head over to the [releases section](https://github.com/alexanderwe/checksum-validator/releases) and download the latest distribution.
1618

app/lib/i18n/de-AT.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"save checks": "Checks speichern",
4141
"save check clipboard": "Checksum in der Zwischenablage speichern",
4242
"settings": "Einstellungen",
43+
"toggle developer tools": "Öffne Entwickler Werkzeuge",
4344
"tooltip save checks":
4445
"Deine Checks werden in einer kleinen Datenbank gespeichert um sie später noch einmal abrufen zu können",
4546
"tooltip save check clipboard":

app/lib/i18n/de-CH.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"save checks": "Checks speichern",
4141
"save check clipboard": "Checksum in der Zwischenablage speichern",
4242
"settings": "Einstellungen",
43+
"toggle developer tools": "Öffne Entwickler Werkzeuge",
4344
"tooltip save checks":
4445
"Deine Checks werden in einer kleinen Datenbank gespeichert um sie später noch einmal abrufen zu können",
4546
"tooltip save check clipboard":

app/lib/i18n/de.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"save checks": "Checks speichern",
4141
"save check clipboard": "Checksum in der Zwischenablage speichern",
4242
"settings": "Einstellungen",
43+
"toggle developer tools": "Öffne Entwickler Werkzeuge",
4344
"tooltip save checks":
4445
"Deine Checks werden in einer kleinen Datenbank gespeichert um sie später noch einmal abrufen zu können",
4546
"tooltip save check clipboard":

app/lib/i18n/en-US.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"save checks": "Save checks",
4141
"save check clipboard": "Save checksum to clipboard",
4242
"settings": "Settings",
43+
"toggle developer tools": "Toggle Developer Tools",
4344
"tooltip save checks":
4445
"Your checks are getting saved into a small database, so you can always remember them",
4546
"tooltip save check clipboard":

app/lib/i18n/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"save checks": "Save checks",
4141
"save check clipboard": "Save checksum to clipboard",
4242
"settings": "Settings",
43+
"toggle developer tools": "Toggle Developer Tools",
4344
"tooltip save checks":
4445
"Your checks are getting saved into a small database, so you can always remember them",
4546
"tooltip save check clipboard":

app/main/src/Checksum.ts

+41-82
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
import * as child from 'child_process';
1+
import * as crypto from 'crypto';
2+
import * as fs from 'fs';
23
import electronLog from 'electron-log';
34
import { IChecksum, ChecksumAlgorithm } from './Database';
45
export default class Checksum {
6+
/**
7+
* @function fileHash
8+
* @param filepath
9+
* @param algorithm
10+
* @desc Creates the hash of a file with a specufued hash algorithm. Uses Node's crypto module.
11+
* @return {Promise.string} The calculation result
12+
*/
13+
static fileHash(filepath, algorithm): Promise<string> {
14+
return new Promise((resolve, reject) => {
15+
if (!filepath) {
16+
reject(new Error());
17+
}
18+
19+
let hashing = crypto.createHash(algorithm);
20+
try {
21+
let stream = new fs.ReadStream(filepath);
22+
stream.on('data', function(data) {
23+
hashing.update(data);
24+
});
25+
stream.on('end', function() {
26+
const hash = hashing.digest('hex');
27+
electronLog.info(
28+
`Computed ${algorithm} of ${filepath} result: ${hash}`,
29+
);
30+
return resolve(hash);
31+
});
32+
} catch (error) {
33+
electronLog.error(
34+
`Error while computing ${algorithm} of ${filepath} : ${error}`,
35+
);
36+
return reject('calc fail');
37+
}
38+
});
39+
}
40+
541
/**
642
* @function sha512
743
* @param {string} filepath: path to the file
844
* @desc Computes sha512 hash of the given file using shasum
945
* @return {Promise.string} The calculation result
1046
*/
1147
public static sha512(filepath: string): Promise<string> {
12-
return new Promise<string>((resolve, reject) => {
13-
child.exec(
14-
'shasum -a 512 ' + filepath.replace(/ /g, '\\ '),
15-
(error, stdout, stderr) => {
16-
const checksum = stdout.split(' ')[0].trim();
17-
if (error) {
18-
electronLog.error(
19-
'Error while computing SHA512 of ' + filepath + ' : ' + error,
20-
);
21-
reject(error);
22-
} else {
23-
electronLog.info(
24-
'Computed SHA512 of ' + filepath + ' result: ' + checksum,
25-
);
26-
resolve(checksum);
27-
}
28-
},
29-
);
30-
});
48+
return Checksum.fileHash(filepath, 'sha512');
3149
}
3250

3351
/**
@@ -37,30 +55,7 @@ export default class Checksum {
3755
* @return {Promise.string} The calculation result
3856
*/
3957
public static sha256(filepath: string): Promise<string> {
40-
return new Promise<string>((resolve, reject) => {
41-
if (!filepath) {
42-
reject(new Error());
43-
}
44-
45-
child.exec(
46-
'shasum -a 256 ' + filepath.replace(/ /g, '\\ '),
47-
(error, stdout, stderr) => {
48-
const checksum = stdout.split(' ')[0].trim();
49-
50-
if (error) {
51-
electronLog.error(
52-
'Error while computing sha256 of ' + filepath + ' : ' + error,
53-
);
54-
reject(error);
55-
} else {
56-
electronLog.info(
57-
'Computed sha256 of ' + filepath + ' result: ' + checksum,
58-
);
59-
resolve(checksum);
60-
}
61-
},
62-
);
63-
});
58+
return Checksum.fileHash(filepath, 'sha256');
6459
}
6560

6661
/**
@@ -70,25 +65,7 @@ export default class Checksum {
7065
* @return {Promise.string} The calculation result
7166
*/
7267
public static sha1(filepath: string): Promise<string> {
73-
return new Promise<string>((resolve, reject) => {
74-
child.exec(
75-
'openssl sha1 ' + filepath.replace(/ /g, '\\ '),
76-
(error, stdout, stderr) => {
77-
const checksum = stdout.split('= ')[1].trim();
78-
if (error) {
79-
electronLog.error(
80-
'Error while computing sha1 of ' + filepath + ' : ' + error,
81-
);
82-
reject(error);
83-
} else {
84-
electronLog.info(
85-
'Computed sha1 of ' + filepath + ' result: ' + checksum,
86-
);
87-
resolve(checksum);
88-
}
89-
},
90-
);
91-
});
68+
return Checksum.fileHash(filepath, 'sha1');
9269
}
9370

9471
/**
@@ -98,25 +75,7 @@ export default class Checksum {
9875
* @return {Promise.string} The calculation result
9976
*/
10077
public static md5(filepath: string): Promise<string> {
101-
return new Promise<string>((resolve, reject) => {
102-
child.exec(
103-
'openssl md5 ' + filepath.replace(/ /g, '\\ '),
104-
(error, stdout, stderr) => {
105-
const checksum = stdout.split('= ')[1].trim();
106-
if (error) {
107-
electronLog.error(
108-
'Error while computing md5 of ' + filepath + ' : ' + error,
109-
);
110-
reject(error);
111-
} else {
112-
electronLog.info(
113-
'Computed md5 of ' + filepath + ' result: ' + checksum,
114-
);
115-
resolve(checksum);
116-
}
117-
},
118-
);
119-
});
78+
return Checksum.fileHash(filepath, 'md5');
12079
}
12180

12281
public static allChecksums(filepath: string): Promise<IChecksum[]> {

app/main/src/IPCHandler.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default class IPCHandler {
2626
.on(Events.CHECKSUM, async (event: any, arg: any) => {
2727
event.sender.send(Events.CHECKSUM, {}); // main received event and acknowledge it to renderer
2828
console.log(arg);
29-
const calculateAll = event.calculateAll;
3029
let checksumResultString: string;
3130
let didMatch: boolean;
3231
let error: boolean;
@@ -52,6 +51,8 @@ export default class IPCHandler {
5251
error = true;
5352
}
5453

54+
console.log(checksumResultString);
55+
5556
didMatch = checksumResultString === arg.checksum ? true : false;
5657

5758
// Only save to clipboard if checksumResultString is available

0 commit comments

Comments
 (0)