-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add over-write for Windows and Linux OS #54
Comments
Deleting files is something that each file system sucks at in unique ways. I would recommend pulling in
function createWindowsShortcut () {
// Because we only specify Windows code in this function,
// there is no point to run it from other platforms
if (process.platform !== 'win32') {
return;
}
// Imports
const path = require('path');
const createDesktopShortcut = require('create-desktop-shortcuts');
const fs = require('fs-extra');
// Variables/settings
const name = 'My App Name';
const outputPath = 'C:\\some\\folder';
const outputFile = path.join(outputPath, name + '.lnk');
// If the file already exists, it will be deleted first
fs.removeSync(outputFile);
// This returns true if the shortcut was created successfully
const created = createDesktopShortcut({
windows: {
filePath: 'C:\\path\\to\\executable.exe',
outputPath,
name
}
);
// if there was an issue creating the shortcut, throw
if (!created) {
throw 'Shortcut failed to create';
}
}
// because both the delete and create are synchronous, we use a try/catch
try {
createWindowsShortcut();
} catch (err) {
console.log('Failed to either delete the old shortcut or create the new one');
console.error(err);
}
|
But I need to extract icon path and target file path of the previous shortcut too , how can I extract it?
…________________________________
From: The Jared Wilcurt ***@***.***>
Sent: Friday, January 28, 2022 8:07:34 PM
To: nwutils/create-desktop-shortcuts ***@***.***>
Cc: Titan ***@***.***>; Author ***@***.***>
Subject: Re: [nwutils/create-desktop-shortcuts] Add over-write for Windows and Linux OS (Issue #54)
Deleting files is something that each file system sucks at in unique ways. I would recommend pulling in fs-extra and using it to delete the file first, then use create-desktop-shortctuts. fs-extra has tons of code to handle all the weird edgecases you run into when trying to delete a file. Also you don't need to check if the file exists first before using it.
npm install --save fs-extra create-desktop-shortcuts
function createWindowsShortcut () {
// Because we only specify Windows code in this function,
// there is no point to run it from other platforms
if (process.platform !== 'win32') {
return;
}
// Imports
const path = require('path');
const createDesktopShortcut = require('create-desktop-shortcuts');
const fs = require('fs-extra');
// Variables/settings
const name = 'My App Name';
const outputPath = 'C:\\some\\folder';
const outputFile = path.join(outputPath, name + '.lnk');
// If the file already exists, it will be deleted first
fs.removeSync(outputFile);
// This returns true if the shortcut was created successfully
const created = createDesktopShortcut({
windows: {
filePath: 'C:\\path\\to\\executable.exe',
outputPath,
name
}
);
// if there was an issue creating the shortcut, throw
if (!created) {
throw 'Shortcut failed to create';
}
}
// because both the delete and create are synchronous, we use a try/catch
try {
createWindowsShortcut();
} catch (err) {
console.log('Failed to either delete the old shortcut or create the new one');
console.error(err);
}
fs-extra is a pretty bulky dependency for me to pull in to this library, since this is the first time this has been requested since 2019, I'd prefer to not increase the library size if it's something most people don't need.
—
Reply to this email directly, view it on GitHub<#54 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AU6ZV532J4TZUYHIR7IBGXDUYKS25ANCNFSM5NAWFQEA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
So I think what you want is to:
So the problem is you are lacking a library to do step 1. I think I can make that. gimme a day |
Okay, maybe less than a day. You can use this library now, and pair it with the code above. |
I'm creating a software with nodejs and I need to over-write shortcuts in it , I found nothing to read Data from a .lnk file else i would have used fs and did it, Could you please Try adding overwrite for windows or something which gives info of the shortcut.
The text was updated successfully, but these errors were encountered: