steam-manifest-tools 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/include/lib.js +37 -21
  2. package/package.json +1 -1
package/include/lib.js CHANGED
@@ -119,9 +119,11 @@ module.exports = {
119
119
  if (file.flags & 64) {
120
120
  continue;
121
121
  }
122
- if (fs.existsSync(path.join(installDir, file.filename))) {
123
- const readSteam = await fsPromises.open(path.join(installDir, file.filename), "r");
122
+ const filename = file.filename.replace(/\\/g, "/");
123
+ if (fs.existsSync(path.join(installDir, filename))) {
124
+ const readSteam = await fsPromises.open(path.join(installDir, filename), "r");
124
125
  let chunk_i = 0;
126
+ const writePromises = [];
125
127
  for (const chunk of file.chunks) {
126
128
  if (!fs.existsSync(`depot/${manifest.depot_id}/chunk/${chunk.sha}`)) {
127
129
  let chunkBuf = Buffer.alloc(chunk.cb_original);
@@ -132,14 +134,18 @@ module.exports = {
132
134
  if (sha1(chunkBuf) == chunk.sha) {
133
135
  chunkBuf = compress(chunkBuf);
134
136
  chunkBuf = SteamCrypto.symmetricEncrypt(chunkBuf, depotKey);
135
- await fsPromises.writeFile(`depot/${manifest.depot_id}/chunk/${chunk.sha}`, chunkBuf);
137
+ const writePromise = fsPromises.writeFile(`depot/${manifest.depot_id}/chunk/${chunk.sha}`, chunkBuf);
136
138
  if (onProgress) {
137
- onProgress(file.filename, file_i, manifest.files.length, chunk_i++, file.chunks.length);
139
+ writePromise.then(() => {
140
+ onProgress(filename, file_i, manifest.files.length, chunk_i++, file.chunks.length)
141
+ });
138
142
  }
143
+ writePromises.push(writePromise);
139
144
  }
140
145
  }
141
146
  }
142
147
  await readSteam.close();
148
+ await Promise.all(writePromises);
143
149
  }
144
150
  ++file_i;
145
151
  }
@@ -164,8 +170,9 @@ module.exports = {
164
170
  resolve();
165
171
  }
166
172
  let /*host_i = 0,*/ running = 0;
173
+ const concurrency = hosts.length == 1 ? 4 : (hosts.length * 2);
167
174
  const loop = () => {
168
- while (running < 4) {
175
+ while (running < concurrency) {
169
176
  const path = Object.keys(toDownload)[0];
170
177
  if (!path) {
171
178
  break;
@@ -209,34 +216,43 @@ module.exports = {
209
216
  ContentManifest.decryptFilenames(manifest, depotKey);
210
217
  installDir ??= `install/${manifest.depot_id}/${manifest.gid_manifest}`;
211
218
  fs.mkdirSync(installDir, { recursive: true });
219
+ const promises = [];
212
220
  for (const file of manifest.files) {
213
221
  if (file.flags & 64) {
214
222
  continue;
215
223
  }
216
- const exists = fs.existsSync(path.join(installDir, file.filename));
217
- if (!exists || await sha1file(path.join(installDir, file.filename)) != file.sha_content) {
218
- for (const chunk of file.chunks) {
219
- chunk.offset = parseInt(chunk.offset);
220
- }
221
- file.chunks.sort((a, b) => a.offset - b.offset);
224
+ promises.push((async () => {
225
+ const filename = file.filename.replace(/\\/g, "/");
226
+ const exists = fs.existsSync(path.join(installDir, filename));
227
+ if (!exists || await sha1file(path.join(installDir, filename)) != file.sha_content) {
228
+ for (const chunk of file.chunks) {
229
+ chunk.offset = parseInt(chunk.offset);
230
+ }
231
+ file.chunks.sort((a, b) => a.offset - b.offset);
222
232
 
223
- await fsPromises.mkdir(path.dirname(path.join(installDir, file.filename)), { recursive: true });
224
- const writeStream = await fsPromises.open(path.join(installDir, file.filename), "w");
225
- for (const chunk of file.chunks) {
226
- await writeStream.write(await getChunk(manifest.depot_id, depotKey, chunk.sha));
227
- }
228
- await writeStream.close();
229
- if (onFileWritten) {
230
- onFileWritten(file.filename, exists);
233
+ await fsPromises.mkdir(path.dirname(path.join(installDir, filename)), { recursive: true });
234
+ const writeStream = await fsPromises.open(path.join(installDir, filename), "w");
235
+ for (const chunk of file.chunks) {
236
+ await writeStream.write(await getChunk(manifest.depot_id, depotKey, chunk.sha));
237
+ }
238
+ await writeStream.close();
239
+ if (onFileWritten) {
240
+ onFileWritten(filename, exists);
241
+ }
231
242
  }
232
- }
243
+ })());
233
244
  }
245
+ await Promise.all(promises);
234
246
  },
235
247
  verifyChunks: async (depotId, depotKey, onDeletedFile) => {
236
248
  const files = await getFiles(`depot/${depotId}/chunk`);
237
- const promises = [];
249
+ let promises = [];
238
250
  for (const file of files) {
239
251
  const hash = file.substr(file.length - 40);
252
+ if (promises.length > 40) {
253
+ await Promise.all(promises);
254
+ promises = [];
255
+ }
240
256
  promises.push(getFileContents(file).then(async data => {
241
257
  try {
242
258
  data = SteamCrypto.symmetricDecrypt(data, depotKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steam-manifest-tools",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "main": "include/lib.js",
5
5
  "repository": {
6
6
  "type": "git",