Skip to content

Commit

Permalink
Updated to include write permission check
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Jul 22, 2018
1 parent c72e5ac commit 7f3ec3e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/folder_select.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h5>Download Folder:</h5>
</div>
</div>
</div>

<p><span id="errorText"> </span></p>

<button id="continue-button" type="button" style="margin: 20px auto;display: block"
class="btn btn-primary">Continue
Expand Down
27 changes: 23 additions & 4 deletions app/folder_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ $(() => {
const shell = require('electron').shell;
const win = remote.getCurrentWindow();
const configPath = path.join(app.getPath('userData'), 'config.json');
const versionInformationURL = 'https://www.realitymod.com/version/versiontest.json';

document.getElementById('download-storage-location-text').style.borderColor = 'black';
$('#download-storage-location-text').attr('value', downloadsPath);
getVersionBig(function(version){
$('#prbf2-version').text(version);
Expand All @@ -19,14 +21,32 @@ $(() => {
properties: ['openDirectory', 'createDirectory']
});
if (downloadsPathTemp !== undefined) {
downloadsPath = downloadsPathTemp[0]
try {
fs.writeFileSync(downloadsPathTemp[0] + '\\test_write_access.pr', 'PR:BF2 Download Assistant - Write access test file. You can remove this file!', 'utf-8');
fs.unlinkSync(downloadsPathTemp[0] + '\\test_write_access.pr');
downloadsPath = downloadsPathTemp[0];
$('#download-storage-location-text').attr('value', downloadsPath);
$('#errorText').text('');
document.getElementById('download-storage-location-text').style.backgroundColor = '#e9ecef';
document.getElementById('download-storage-location-text').style.color = '#495057';
document.getElementById('download-storage-location-text').style.borderColor = 'black';
document.getElementById('continue-button').disabled = false;
}
catch(e) {
document.getElementById('continue-button').disabled = true;
downloadsPath = undefined;
document.getElementById('download-storage-location-text').style.backgroundColor = 'rgb(255,179,184)';
document.getElementById('download-storage-location-text').style.color = 'rgb(107,29,37)';
document.getElementById('download-storage-location-text').style.borderColor = 'red';
$('#download-storage-location-text').attr('value', downloadsPathTemp[0]);
$('#errorText').text('Please choose a different download folder. No write privileges to this folder.');
}
}
$('#download-storage-location-text').attr('value', downloadsPath);
}

function getVersionBig(handleData) {
$.ajax({
url: "https://www.realitymod.com/version/version.json",
url: versionInformationURL,
success:function(data) {
handleData(data.version_big);
}
Expand Down Expand Up @@ -56,7 +76,6 @@ $(() => {
win.loadFile('./app/download.html')

}

document.querySelector('#continue-button').addEventListener('click', onContinueButtonPress);
document.querySelector('#browse-button').addEventListener('click', onBrowseButtonPress);
document.querySelector('#close-button').addEventListener('click', onCloseButtonPress);
Expand Down
12 changes: 12 additions & 0 deletions app/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ h5 {
cursor: default;
}

.btn-primary:disabled {
background: linear-gradient(to bottom, #3298cb, #03699c);
color: black;
border: none;
font-weight: 500;
}

#titlebar-container {
background-color: black;
position: relative;
Expand Down Expand Up @@ -119,4 +126,9 @@ h5 {

#torrent-pause, #torrent-start, #minimize-button, #close-button{
cursor: pointer;
}

#errorText{
color: #ff4f5c;
padding-left:14px;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "PRBF2-Download-Assistant",
"version": "1.0.0",
"description": "An automatic download tool for Project Reality: Battlefield 2",
"version": "1.1.0",
"description": "Download tool for PR:BF2",
"main": "./app/main.js",
"dependencies": {
"humanize-duration": "latest",
Expand Down

0 comments on commit 7f3ec3e

Please sign in to comment.