Windows fixes

This commit is contained in:
Scott E. Graves
2018-12-10 13:32:26 -06:00
parent 61b2f6e6f6
commit 29a72f4707
2 changed files with 60 additions and 56 deletions

View File

@@ -65,8 +65,9 @@ function createWindow() {
// Unmount all items
for (const i in mountedLocations) {
const data = mountedData[mountedLocations[i]];
helpers.stopMountProcess(data.DataDirectory, data.Version, data.StorageType);
helpers.stopMountProcessSync(data.DataDirectory, data.Version, data.StorageType);
}
mountedLocations = [];
mountedData = {};
});
@@ -275,50 +276,49 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
driveLetters[provider] = [];
}
const grabDriveLetters = (hsLocation, siaLocation, siaPrimeLocation) => {
const grabDriveLetters = (locations) => {
for (let i = 'c'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) {
const drive = (String.fromCharCode(i) + ':').toUpperCase();
if (!(hsLocation.startsWith(drive) || siaLocation.startsWith(drive) || siaPrimeLocation.startsWith(drive))) {
let driveInUse = false;
for (const provider of Constants.PROVIDER_LIST) {
driveInUse = locations[provider].startsWith(drive);
if (driveInUse)
break;
}
if (!driveInUse) {
try {
if (!fs.existsSync(drive)) {
driveLetters.Hyperspace.push(drive);
driveLetters.Sia.push(drive);
driveLetters.SiaPrime.push(drive);
for (const provider of Constants.PROVIDER_LIST) {
driveLetters[provider].push(drive);
}
}
} catch (e) {
}
}
}
if (hsLocation.length > 0) {
if (!driveLetters.Hyperspace.find((driveLetter) => {
return driveLetter === hsLocation;
for (const provider of Constants.PROVIDER_LIST) {
if (locations[provider].length > 0) {
if (!driveLetters[provider].find((driveLetter) => {
return driveLetter === locations[provider];
})) {
driveLetters.Hyperspace.push(hsLocation);
driveLetters[provider].push(locations[provider]);
}
}
if (siaLocation.length > 0) {
if (!driveLetters.Sia.find((driveLetter) => {
return driveLetter === siaLocation;
})) {
driveLetters.Sia.push(siaLocation);
}
}
if (siaPrimeLocation.length > 0) {
if (!driveLetters.SiaPrime.find((driveLetter) => {
return driveLetter === siaPrimeLocation;
})) {
driveLetters.SiaPrime.push(siaPrimeLocation);
}
}
};
const setImage = (hsLocation, siaLocation, siaPrimeLocation) => {
const setImage = (locations) => {
if (os.platform() === 'win32' || os.platform() === 'linux') {
let driveInUse = false;
for (const provider of Constants.PROVIDER_LIST) {
driveInUse = locations[provider].length > 0;
if (driveInUse)
break;
}
let image;
if ((siaLocation.length > 0) || (hsLocation.length > 0) || (siaPrimeLocation.length > 0)) {
if (driveInUse) {
image = nativeImage.createFromPath(path.join(__dirname, '/build/logo_both.png'));
} else {
image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png'));
@@ -332,39 +332,28 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
helpers
.detectRepertoryMounts(dataDirectory, data.Version)
.then((results) => {
let hsLocation = results.Hyperspace.Location;
let siaLocation = results.Sia.Location;
if (!results.SiaPrime) {
results.SiaPrime = {
let data = {};
let locations = {};
for (const provider of Constants.PROVIDER_LIST) {
data[provider] = results[provider] ? results[provider] : {
Active: false,
Location: '',
PID: -1,
};
if (data[provider].PID !== -1) {
expectedUnmount[provider] = false;
}
let siaPrimeLocation = results.SiaPrime.Location;
locations[provider] = data[provider].Location;
}
if (os.platform() === 'win32') {
hsLocation = hsLocation.toUpperCase();
siaLocation = siaLocation.toUpperCase();
siaPrimeLocation = siaPrimeLocation.toUpperCase();
grabDriveLetters(hsLocation, siaLocation, siaPrimeLocation);
grabDriveLetters(locations);
}
if (results.Hyperspace.PID !== -1) {
expectedUnmount['Hyperspace'] = false;
}
if (results.Sia.PID !== -1) {
expectedUnmount['Sia'] = false;
}
if (results.SiaPrime.PID !== -1) {
expectedUnmount['SiaPrime'] = false;
}
setImage(hsLocation, siaLocation, siaPrimeLocation);
setImage(locations);
standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, {
DriveLetters: driveLetters,
Locations: {
Hyperspace: hsLocation,
Sia: siaLocation,
SiaPrime: siaPrimeLocation,
}
Locations: locations,
});
})
.catch(error => {
@@ -541,6 +530,7 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
StorageType: data.StorageType,
};
const errorHandler = (pid, error) => {
console.log(pid, error);
if (mountedLocations.indexOf(data.Location) !== -1) {
mountedLocations.splice(mountedLocations.indexOf(data.Location), 1);
delete mountedData[data.Location];

View File

@@ -198,8 +198,6 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
clearTimeout(timeout);
exitCallback(code, pid);
});
process.unref();
});
};
@@ -466,6 +464,22 @@ module.exports.stopMountProcess = (directory, version, storageType) => {
Code: code,
});
});
process.unref();
});
};
module.exports.stopMountProcessSync = (directory, version, storageType) => {
const processOptions = {
detached: true,
shell: true,
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = ['-unmount'];
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
}
const process = new spawn(command, args, processOptions);
process.unref();
};