Giter Club home page Giter Club logo

mslinks's People

Contributors

blackoverlord666 avatar degubi avatar dmitriishamrikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mslinks's Issues

JDK11 Compat

Hi,

Thanks for this fantastic library. :)

The latest mslinks release fails any dependant project that is built with JDK11, the error is as follows:

    [javac] import mslinks.ShellLink;
    [javac]               ^
    [javac]   bad class file: /home/runner/work/tray/tray/lib/mslinks-1.0.7.jar(/mslinks/ShellLink.class)
    [javac]     class file has wrong version 58.0, should be 55.0
    [javac]     Please remove or make sure it appears in the correct subdirectory of the classpath.

Personally, for historical purposes, I've kept JDK8 level compatible with most of my project. I could probably move permanently to JDK11 but the above suggests JDK13 which will break a lot of projects requiring this library (including my own)

Was this change intended?

file handle leak

at ShellLink.java,while file isn't a mslink , in.close() will not execture, so file handle leak !!!
public ShellLink(InputStream in) throws IOException, ShellLinkException { this(new ByteReader(in)); in.close(); }

License

Please add a license to this project so it can (or can't) be reused.

Library version

Hi!
The latest version of the library that is published here, is not available on Maven central. So, if you can update it, it will be very helpful.
Thank you!

Artifact published to maven central

Hey,
I've taken the liberty to publish your library to maven central. That means that a binary distribution is now available for public download here and that means again that it will be much easier for devs to use your library in maven.

That's it, no further action is required from you, or almost no action. I would be really glad if you could write something along the lines of the beginning of the readme of my fork in your readme to tell the world about the artifact on maven central.

Thanks for helping me and have a nice weekend,
vatbub

Modularization

Add a module-info.java file to the source directory for the Java 9 module system.
I don't know which java version this library requires, but adding this file will require at least Java 9.
We need this module file, because without it it's very hard to create jlink images with this library.
The file should look something like this:

module shellinks {
    exports mslinks;
    exports io;
    exports mslinks.data;
    exports mslinks.extra;
}
  • This defines that the module name for the jar should be: "shellinks" (can change)
  • This means that all packages are exported (no encapsulation on package level).

I can create a PR for this if this is fine.

Regression with deprecated ShellLink.createLink(...)

This code worked in 1.0.4, but is broken in 1.0.7:

ShellLink.createLink("C:\\Windows\\notepad.exe", "C:\\Users\\Owner\\Desktop\\Start Notepad.lnk");

Error:

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <<> at index 0: <unknown>
	at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
	at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
	at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232)
	at java.base/java.nio.file.Path.of(Path.java:147)
	at java.base/java.nio.file.Paths.get(Paths.java:69)
	at mslinks.ShellLinkHelper.saveTo(ShellLinkHelper.java:153)
	at mslinks.ShellLink.saveTo(ShellLink.java:330)
	at mslinks.ShellLink.createLink(ShellLink.java:366)
	at LinkBug.main(LinkBug.java:5)

Workaround:

  • Switch away from the deprecated API to the new API:
ShellLinkHelper.createLink("C:\\Windows\\notepad.exe", "C:\\Users\\Owner\\Desktop\\Start Notepad.lnk");

Unsupported CLSID Exception for `59031A47-3F72-44A7-89C5-5595FE6B30EE` when trying to resolve lnk

Heya DmitriiShamrikov,

I've recently stumbled upon an UnsupportedCLSIDException for 59031A47-3F72-44A7-89C5-5595FE6B30EE, when trying to resolve a lnk from a users Desktop pointing towards folders or files on another drive.

My impression was that a Windows lnk could be resolved to its actual target by calling

new ShellLink(file).resolveTarget()

where file represents the lnk we want to resolve.

If I'm doing this the wrong way, I'd appreciate a pointer in the right direction.

Thanks in advance!

Stay safe and stay awesome.
Cheers,
Griefed

Target does not change saving to an existing link

I am trying to update the target on an existing link using this code:

    String one = "C:"+File.separator+"Tmp"+File.separator+"1.txt";  // Already exists
    String two = "C:"+File.separator+"Tmp"+File.separator+"2.txt";  // Already exists
    String link = "C:"+File.separator+"Tmp"+File.separator+"link.txt.lnk";
    ShellLink.createLink(one,link);
    ShellLink slink = new ShellLink(link);
    slink.getLinkInfo().setLocalBasePath(two);
    slink.saveTo(link);

At the end of this operation, the link is still pointing to file 1.txt and the program did not generate an error to indicate anything is wrong. I think the code should either update the link or throw an error telling the user the operation did not complete as anticipated.

Ant-Task

Nice feature would be an usable Ant-Task. Many many people are searching for a proper solution for creating lnk files with Ant.

Dependencies resolution

Hello,

https://dl.bintray.com is no longer available

[ERROR] Failed to execute goal on project ant: Could not resolve dependencies for project com.wac.core:ant:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.github.vatbub:mslinks:jar:1.0.6.1: Failed to read artifact descriptor for com.github.vatbub:mslinks:jar:1.0.6.1: Could not transfer artifact com.github.vatbub:parentPom:pom:2.0.1-alpha2 from/to bintray-vatbub-fokprojectsReleases (https://dl.bintray.com/vatbub/fokprojectsReleases): Authorization failed for https://dl.bintray.com/vatbub/fokprojectsReleases/com/github/vatbub/parentPom/2.0.1-alpha2/parentPom-2.0.1-alpha2.pom 403 Forbidden -> [Help 1]

Not working compiled project java 1.7

In this time we like to use it, but can't at Java compilation 1.7 because Java 1.8 functions or lambdas are used.

Please make a Java 1.7 compiled code version.

Just avoid lambda, method group calls, streams and defaults in interfaces (constants in interfaces are ok)
Then compile it with Java 1.7 SDK.

Tank you @BlackOverlord666

Create links on Unix/Linux

Hi!

While your code works brilliantly on Windows, it would be awesome to get this running on Linux. I've seen plenty of checks and input modifications in ShellLink.java, they're all doomed to fail or raise NPEs in a Linux environment.

Any idea on how to achieve this? You'd somehow offer a way to override all checks and just trust the dev that what he/she puts in is really valid.

Cheers

André

PS: Reason behind: I'd like to create 100s of links out of an oracle database.

Doesn't automaticlly set icon

When it creates a short cut it doesn't set the shortcut to have the icon. If I right click on the short cut and click on "change icon...", the path I set pointing to the icon is there, as well as the icon. Clicking OK sets it. Is there a way to have it create the icon with the image set from the start?

Put mslinks into MavenCentral

Hi there! I think it would be great if mslinks was available in mavencentral. I've got a template that I use to auto-upload to bintray and mavencentral, add the javadocs to gh-pages, etc. It would take me about an hour for me to put my fork/ up as "com.diffplug.mslinks".

If you'd like, I can apply the template to your project and you can upload it yourself under your own prefix.

Here's what a project looks like under the template:
https://github.com/diffplug/durian

You'd need to create a Sonatype account, bintray account, and Travis CI account, and the project would use gradle as its build system. If you're interested in a PR let me know, and if not I'll put it up as "com.diffplug.mslinks" (or something else if you prefer).

can't install

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project mslinks: Fatal error compiling
image

target does not allow arguments

I want to set some thing like "cmd.exe /c my-command" as a target, I get an exception as the createLink tries to resolve it as avalid path only (Paths.get(...))

Usage stats

Hey,
as I know that getting feedback is one of the best parts of programming and content creation so I thought to share some download stats from Maven Central and the Bintray repo. Although we're not in any top 10 list yet, but we have a good average of 90 downloads per month (peak of 227 in March) coming from 40 unique IPs (average).
In my opinion, that shows that you did a good job with the lib :)

Class file has wrong version 58.0, should be 52.0

Hi!,
I'm having troubles getting the built jar from maven central with Gradle. I'm working with Java 1.8 (class version 52.0). I couldn't find any mention of it being Java 14+ only, so I'm making an issue.

I'm using the following Gradle code:

dependencies{
    // ...
    implementation("com.github.vatbub:mslinks:1.0.6")
    // ...
}

It's the same shown on the project's maven central page.
I'm getting the following error:

[...]\manager\control\Controller.java:13: error: cannot access ShellLink
import mslinks.ShellLink;
              ^
  bad class file: [...]\.gradle\caches\modules-2\files-2.1\com.github.vatbub\mslinks\1.0.6\926d37969cba023bb65a93f3bf038585aeab6312\mslinks-1.0.6.jar(mslinks/ShellLink.class)
    class file has wrong version 58.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

PatternSyntaxError when there is environment variable with backslashes

In case there is a environment variable name, that contains backslashes, the method createLink fails.

java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 12
%\\.\Global\Motherboard Resources\PATHS%
            ^
at java.base/java.util.regex.Pattern.error(Pattern.java:2015)
at java.base/java.util.regex.Pattern.escape(Pattern.java:2604)
at java.base/java.util.regex.Pattern.atom(Pattern.java:2273)
at java.base/java.util.regex.Pattern.sequence(Pattern.java:2197)
at java.base/java.util.regex.Pattern.expr(Pattern.java:2056)
at java.base/java.util.regex.Pattern.compile(Pattern.java:1778)
at java.base/java.util.regex.Pattern.<init>(Pattern.java:1427)
at java.base/java.util.regex.Pattern.compile(Pattern.java:1094)
at mslinks.ShellLink.resolveEnvVariables(ShellLink.java:395)
at mslinks.ShellLink.setTarget(ShellLink.java:336)
at mslinks.ShellLink.createLink(ShellLink.java:380)

Looks like just adding replace("\\", "\\\\"); might fix the problem

ItemID type 46 (0x2E)

Hi,
I get this Exception:

mslinks.ShellLinkException: unsupported ItemID type
at mslinks.data.ItemID.(ItemID.java:144)
at mslinks.LinkTargetIDList.(LinkTargetIDList.java:71)
at mslinks.ShellLink.(ShellLink.java:113)
at mslinks.ShellLink.(ShellLink.java:105)

This happens on Windows 10.
I created a directory shortcut using the context menu option. It's very simple shortcut.
I remember this used to work just fine when I started using the library. I'm wondering if something changed with the latest Windows updates.

Thanks,
Alex.

Set "Run as Admin"

Hi, Sorry to disturb you but I couldn't find it in doc or anything.
Does your API allow to set the Property "Run as Admin" for the shortcut?

Is this a cmd arg?

Index for an icon

Hi,

I'm using your lib to replace some VB code and I encountered this part:

IconLocation = "C:\Windows\system32\SHELL32.dll, 131"

Can I pass that 131 somehow to ShellLink? I tried:

.setIconLocation("C:\\Windows\\system32\\SHELL32.dll, 131")

but it does not work.

NegativeArraySizeException

I believe I've found a bug with new ShellLink("foo.lnk")

What works:

  • Link created with mslinks on Windows 10, Windows XP
  • Link created with NSIS CreateShortCut <link> <exe> <params> <icon> <index> on Windows 10

What doesn't work:

I've attached some sample lnk files for examination here.

For now, the workaround is to catch the exception on Windows XP and optionally rewrite the icon using mslinks when the exception occurs.

Backtrace:

java.lang.NegativeArraySizeException
        at io.ByteReader.readUnicodeString(ByteReader.java:161)
        at mslinks.data.ItemID.<init>(ItemID.java:74)
        at mslinks.LinkTargetIDList.<init>(LinkTargetIDList.java:45)
        at mslinks.ShellLink.<init>(ShellLink.java:90)
        at mslinks.ShellLink.<init>(ShellLink.java:82)
        at mslinks.ShellLink.<init>(ShellLink.java:77)
        at mslinks.ShellLink.<init>(ShellLink.java:69)
        at qz.deploy.WindowsDeploy.hasStartupShortcut(Unknown Source)
        at qz.deploy.DeployUtilities.hasShortcut(Unknown Source)
        at qz.deploy.DeployUtilities.createShortcut(Unknown Source)
        at qz.common.TrayManager.shortcutToggle(Unknown Source)
        at qz.common.TrayManager.lambda$new$2(Unknown Source)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.JToggleButton$ToggleButtonModel.setPressed(Unknown Source)
        at javax.swing.AbstractButton.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
        at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

Releasing to Maven central

Hi all,
I just saw that you added gradle to your project. I am not that familiar with gradle as I am with Maven, hence, I would like to stop releasing mslinks to Maven Central.
So, if anyone feels like taking that job over, feel free to do so 😎
Regards,
Freddie aka vatbub

Version number

Hey, just wondering if you could toss a version number into the code somewhere. Thanks!

Can't set custom icon

I have a .ico that I'm trying to set for the shortcut with this but it won't work. If I manually go into the .lnk properties and set it, it does work. I've checked that the paths are all correct in the code "C:\Users\Jake\Desktop\Folders n' stuff\Korder\sprites\logo.ico". I can create the shortcut just fine and it does open the target file but I just can't set the icon.
I've tried "ShellLink.createLink(p,p1).setIconLocation(p2);" with p being the target file, p1 being the shortcut, and p2 being the icon and I've tried
ShellLink sl = ShellLink.createLink(p,p1);
sl.setIconLocation(p2);
Edit: Just tried "%USERPROFILE%\Desktop\Folders n' stuff\Korder\sprites\logo.ico" and that didn't work either.
Edit: I got it to work. I had to put .saveTo(p1) at the end.

Character Encoding Incorrect

here is my .lnk file,one is japanese,another is chinese
QQ截图20210815145555

here is my code
ShellLink shellLink = new ShellLink(file); System.out.println(shellLink.getLinkInfo().getLocalBasePath());
and console out put:
O:\game\J�c����B\Start.exe A:\�½��ı��ĵ�.txt
output

my os is windows10 x64 Chinese version.

here is the sample .lnk files.
lnk.zip

when I change your code
localBasePath = data.readString(pos + size - data.getPosition());
to
localBasePath = new String(bytes,"GBK");
the "新建文本文档" file can be correct printlned on console,but another file is incorrect. I change Charset to 'Shift_JIS' the other "JD温泉。" file can be correct printlned.

is there a way to read the .lnk file's Charset ?

Characters in parameters to filepath not accepted

This is an actual text in a shortcut target

I:\DXALW32.EXE -cUK "-dI:;I:\Country\UK" -uABC

I have then created this

ShellLink sl = ShellLink.createLink("i:\DXALW32.EXE -cUK "-dI:\;I:\Country\UK" -uABC")

but it gives this error:

java.nio.file.InvalidPathException: Illegal char <"> at index 20: i:\DXALW32.EXE -cUK "-dI:;I:\Country\UK" -uABC

How am I supposed to format the options correctly to make it work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.