This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Huge number of updates for cloud sync!
- Loading branch information
Showing
11 changed files
with
504 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import {join as joinPath, sep as pathSep} from "path"; | ||
import {app} from "electron"; | ||
import {randomBytes} from "crypto"; | ||
import * as request from "request"; | ||
import * as unzip from "@zudo/unzipper"; | ||
import {createWriteStream, readdirSync, emptyDirSync, mkdirsSync, removeSync} from "fs-extra"; | ||
import Config from "../utils/Config"; | ||
import * as archiver from "archiver"; | ||
|
||
export default class InstallSync { | ||
|
||
/** | ||
* Install the save data from Firebase into an existing install | ||
* @param folderName The folder name | ||
* @param saveDataURL The URL | ||
*/ | ||
public static installSaveData(folderName: string, saveDataURL: string): Promise<void> { | ||
return new Promise((ff, rj) => { | ||
const tempZipPath: string = joinPath(app.getPath("temp"), "ddmm" + randomBytes(8).toString("hex") + ".zip"); | ||
|
||
request(saveDataURL).pipe(createWriteStream(tempZipPath)).on("close", () => { | ||
// mod is downloaded | ||
|
||
let saveDataPath: string = joinPath(Config.readConfigValue("installFolder"), "installs", folderName, "appdata"); | ||
|
||
if (process.platform === "win32") { | ||
saveDataPath = joinPath(saveDataPath, "RenPy"); | ||
} else if (process.platform === "darwin") { | ||
saveDataPath = joinPath(saveDataPath, "Library", "RenPy"); | ||
} else { | ||
saveDataPath = joinPath(saveDataPath, ".renpy"); | ||
} | ||
|
||
emptyDirSync(saveDataPath); // clear the folder | ||
|
||
const zip = unzip(tempZipPath); | ||
|
||
zip.on("file", file => { | ||
const pathParts = file.path.split("/"); | ||
|
||
const fileName = pathParts.pop(); | ||
mkdirsSync(joinPath(saveDataPath, pathParts.join(pathSep))); | ||
|
||
console.log(joinPath(saveDataPath, pathParts.join(pathSep))); | ||
|
||
// write the file | ||
file.openStream((err, stream) => { | ||
if (err) { | ||
rj(err); | ||
} | ||
stream.pipe(createWriteStream(joinPath( | ||
saveDataPath, | ||
pathParts.join(pathSep), fileName))); | ||
}); | ||
}); | ||
|
||
zip.on("close", () => { | ||
removeSync(tempZipPath); | ||
ff(); | ||
}); | ||
}).on("error", err => { | ||
rj(err); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Compresses the save data of a mod into a .zip and returns the path | ||
* @param folderName The folder name | ||
*/ | ||
public static compressSaveData(folderName: string): Promise<string> { | ||
return new Promise((ff, rj) => { | ||
const tempZipPath: string = joinPath(app.getPath("temp"), "ddmm" + randomBytes(8).toString("hex") + ".zip"); | ||
|
||
let saveDataPath: string = joinPath(Config.readConfigValue("installFolder"), "installs", folderName, "appdata"); | ||
|
||
if (process.platform === "win32") { | ||
saveDataPath = joinPath(saveDataPath, "RenPy"); | ||
} else if (process.platform === "darwin") { | ||
saveDataPath = joinPath(saveDataPath, "Library", "RenPy"); | ||
} else { | ||
saveDataPath = joinPath(saveDataPath, ".renpy"); | ||
} | ||
|
||
const output = createWriteStream(tempZipPath); | ||
const zip = archiver("zip"); | ||
|
||
output.on("close", () => { | ||
ff(tempZipPath); | ||
}); | ||
|
||
zip.on("error", err => { | ||
rj(err); | ||
}); | ||
|
||
zip.pipe(output); | ||
zip.directory(saveDataPath, false); | ||
zip.finalize(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.