Skip to content

Commit

Permalink
Merge pull request #25 from NicolasConstant/develop
Browse files Browse the repository at this point in the history
1.1.0 PR
  • Loading branch information
NicolasConstant authored Jul 29, 2021
2 parents 985c573 + 68fe968 commit a70120e
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 60 deletions.
Binary file added docs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions docs/windsailor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MSFS Community Downloader</title>
<style>
body {
background-color: black;
background-color: #24272e;
color: white;
font-family: sans-serif;
}

.intro {
text-align: center;
margin-top: 30px;
}

.resume {
text-align: center;
margin-top: 20px;
}

.link {
display: block;
background-color: orange;
padding: 20px 40px;
border-radius: 20px;
font-size: 20px;
text-decoration: none;
color: black;
font-weight: bold;
margin: auto;
margin-top: 60px;
width: 200px;
}

.link:hover {
background-color: #ffd27e;
}

.sub-link {
display: block;
text-align: center;
color: gray;
padding-top: 10px;
font-size: 14px;
}

.sub-link:hover {
color: white;
}

.bold-inline {
font-weight: bold;
color: white;
}
</style>
</head>

<body>
<div class="intro">Enjoying the app?</div>
<div class="resume">
Some of you asked me to support <span class="bold-inline">flightsim.to</span><br />
and other addon websites in <span class="bold-inline">MSFS Community Downloader</span>.<br/>
<br/>
This was not possible due to the lack of API.<br/>
<br/>
<br/>
<br/>
But I have a surprise for you:<br/>
<br/>
I've made a new app to let you browse your favorite websites<br/>
and still get all the installation automation you love!
</div>

<a class="link" href="https://flightsim.to/file/18195/windsailor" target="_blank">Discover WindSailor</a>
<a class="sub-link" href="https://flightsim.to/file/18195/windsailor" target="_blank">https://flightsim.to/file/18195/windsailor</a>
</body>

</html>
52 changes: 32 additions & 20 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,50 @@ try {

ipcMain.on('download-item', (event, info) => {
(async () => {
info.properties.onProgress = status => event.sender.send("download-progress", { packageId: info.packageId, status: status});

const win = BrowserWindow.getFocusedWindow();
await download(win, info.url, info.properties)
.then(dl => event.sender.send('download-success', dl.getSavePath()));
try {
info.properties.onProgress = status => event.sender.send("download-progress", { packageId: info.packageId, status: status });

const win = BrowserWindow.getFocusedWindow();
await download(win, info.url, info.properties)
.then(dl => event.sender.send('download-success', dl.getSavePath()));
} catch (err) {
event.sender.send('log-error', err);
}
})();
});

ipcMain.on('extract-item', (event, info) => {
(async () => {
const pro = new Promise((resolve, reject) => {
const zip = new AdmZip(info.filePath);
zip.extractAllToAsync(info.extractFolder, true, (err) => {
if (err) reject();
resolve();
try {
const pro = new Promise((resolve, reject) => {
const zip = new AdmZip(info.filePath);
zip.extractAllToAsync(info.extractFolder, true, (err) => {
if (err) reject();
resolve();
});
});
});
await pro;
event.sender.send('extract-success', info);
await pro;
event.sender.send('extract-success', info);
} catch (err) {
event.sender.send('log-error', err);
}
})();
});

ipcMain.on('copy-folder', (event, info) => {
(async () => {
const pro = new Promise((resolve, reject) => {
fse.copy(info.source, info.target, { overwrite: true }, (err) => {
if (err) reject(err);
resolve();
try {
const pro = new Promise((resolve, reject) => {
fse.copy(info.source, info.target, { overwrite: true }, (err) => {
if (err) reject(err);
resolve();
});
});
});
await pro;
event.sender.send('copy-folder-success', info);
await pro;
event.sender.send('copy-folder-success', info);
} catch (err) {
event.sender.send('log-error', err);
}
})();
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msfs-community-downloader",
"version": "1.0.0",
"version": "1.1.0",
"description": "MSFS addin downloader client",
"homepage": "https://github.com/nicolasconstant/msfs-community-downloader",
"author": {
Expand Down
75 changes: 42 additions & 33 deletions src/app/core/services/domain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export class DomainService {
.catch(err => {
console.error(err);
error = err;
x.state = InstallStatusEnum.error;
x.state = InstallStatusEnum.error;
});
});
});
pipeline = pipeline.then(() => {
if(error){
throw(error);
if (error) {
throw (error);
}
});
return pipeline;
Expand All @@ -86,6 +86,7 @@ export class DomainService {
p.availableVersion = remote.availableVersion;
p.assetDownloadUrl = remote.downloadUrl;
p.publishedAt = remote.publishedAt;
p.html_url = remote.html_url;
}

p.state = this.getState(p, local, remote);
Expand Down Expand Up @@ -124,44 +125,52 @@ export class DomainService {
}

async processExtractedFolder(r: FileExtractedInfo): Promise<any> {
const extractedFolder = r.extractFolder;
const addinFolderPath = await this.filesystemService.findAddinFolder(extractedFolder);
try {
const extractedFolder = r.extractFolder;
const addinFolderPath = await this.filesystemService.findAddinFolder(extractedFolder);

if (!addinFolderPath) return;
if (!addinFolderPath) return;

const p = this.packages.find(x => x.id === r.packageId);
const p = this.packages.find(x => x.id === r.packageId);

const communityDir = this.settingsService.getSettings().communityPath;
const folderPath = `${communityDir}\\${p.folderName}`;
const communityDir = this.settingsService.getSettings().communityPath;
const folderPath = `${communityDir}\\${p.folderName}`;

p.state = InstallStatusEnum.installing;
this.app.tick();
p.state = InstallStatusEnum.installing;
this.app.tick();

// Clean up
await this.filesystemService.deleteFolder(folderPath);
// Clean up
await this.filesystemService.deleteFolder(folderPath);

if (p.oldFolderNames && p.oldFolderNames.length > 0) {
p.oldFolderNames.forEach(o => {
(async () => {
const oldFolderPath = `${communityDir}\\${o}`;
await this.filesystemService.deleteFolder(oldFolderPath);
})();
});
}
if (p.oldFolderNames && p.oldFolderNames.length > 0) {
p.oldFolderNames.forEach(o => {
(async () => {
const oldFolderPath = `${communityDir}\\${o}`;
await this.filesystemService.deleteFolder(oldFolderPath);
})();
});
}

this.filesystemService.copyToCommunity(p.id, addinFolderPath, p.folderName);
this.filesystemService.copyToCommunity(p.id, addinFolderPath, p.folderName);
} catch (err) {
console.error(err);
}
}

processCopiedFolder(r: CopyFolderInfo): void {
const p = this.packages.find(x => x.id === r.packageId);
if (p.tempWorkingDir) {
this.filesystemService.deleteFolder(p.tempWorkingDir);
p.tempWorkingDir = null;
try {
const p = this.packages.find(x => x.id === r.packageId);
if (p.tempWorkingDir) {
this.filesystemService.deleteFolder(p.tempWorkingDir);
p.tempWorkingDir = null;
}
this.filesystemService.writeVersionFile(r.target, p.availableVersion);
p.localVersion = p.availableVersion;
p.state = InstallStatusEnum.installed;
this.app.tick();
} catch (err) {
console.error(err);
}
this.filesystemService.writeVersionFile(r.target, p.availableVersion);
p.localVersion = p.availableVersion;
p.state = InstallStatusEnum.installed;
this.app.tick();
}

getPackages(): Package[] {
Expand All @@ -183,7 +192,7 @@ export class DomainService {

this.packages.forEach(x => x.isSelected = false);

const settings = this.settingsService.getSettings();
const settings = this.settingsService.getSettings();
settings.customPackages.push(p);
this.settingsService.saveSettings(settings);

Expand Down Expand Up @@ -335,11 +344,11 @@ export class DomainService {

remove(p: Package): void {
const communityDir = this.settingsService.getSettings().communityPath;

let folderPath = `${communityDir}\\${p.folderName}`;

const customPackageFolder = this.settingsService.getCustomPackageDirectory(p.id);
if(customPackageFolder){
if (customPackageFolder) {
folderPath = `${customPackageFolder}\\${p.folderName}`;
}

Expand Down
20 changes: 20 additions & 0 deletions src/app/core/services/electron/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ export class ElectronService {
this.fs = window.require('fs');
}
}

openWindSailorWindow(): void {
const BrowserWindow = this.remote.BrowserWindow;
const win = new BrowserWindow({
height: 500,
width: 700,
alwaysOnTop: true,
maximizable: false,
});

win.webContents.setWindowOpenHandler(({ url }) => {
window.require('electron').shell.openExternal(url);
return { action: 'deny' };
});

win.menuBarVisible = false;
win.resizable = false;
win.loadURL('https://nicolasconstant.github.io/msfs-community-downloader/windsailor.html');
win.focus();
}
}
9 changes: 8 additions & 1 deletion src/app/core/services/filesystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export class FilesystemService {
}
});

this.electronService.ipcRenderer.on('log-error', (event, arg) => {
if (arg) {
console.error('Node error');
console.error(arg);
}
});

this.checkCleanUpCommunity();
}

Expand All @@ -32,7 +39,7 @@ export class FilesystemService {
.then((dirs: string[]) => {
return dirs.filter(x => x.includes('msfs-downloader___'));
})
.then((filDirs: string[]) => {
.then((filDirs: string[]) => {
for (const d of filDirs) {
const fullPath = `${communityPath}\\${d}`;
this.deleteFolder(fullPath);
Expand Down
6 changes: 4 additions & 2 deletions src/app/core/services/github.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class GithubService {
downloadUrl = asset.browser_download_url;
}

const res = new PackageInfo(lastRelease.tag_name, downloadUrl, lastRelease.published_at);
const res = new PackageInfo(lastRelease.tag_name, downloadUrl, lastRelease.published_at, lastRelease.html_url);
return res;
});
}
Expand All @@ -50,7 +50,8 @@ export class PackageInfo {
constructor(
public availableVersion: string,
public downloadUrl: string,
public publishedAt: Date) { }
public publishedAt: Date,
public html_url: string) { }
}

interface GithubRelease {
Expand All @@ -61,6 +62,7 @@ interface GithubRelease {
assets: GithubAsset[];
zipball_url: string;
published_at: Date;
html_url: string;
}

interface GithubAsset {
Expand Down
1 change: 1 addition & 0 deletions src/app/core/services/packages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class Package {
public localVersion: string;
public availableVersion: string;
public publishedAt: Date;
public html_url: string;

public githubOwner: string;
public githubRepo: string;
Expand Down
Loading

0 comments on commit a70120e

Please sign in to comment.