materialos / Windows-Icon-Pack

This is a public icon pack that anyone and everyone is invited to contribute to.
Other
6 stars 1 forks source link

Automagically Applying Icons #1

Open danielhickman opened 9 years ago

danielhickman commented 9 years ago

~~Maybe this: http://stackoverflow.com/a/1214825/2758250 (dangerous says @crutchcorn)~~

wilkgr76 commented 7 years ago

TBH, it would be better to update the icons of the shortcuts - shortcuts can be given a custom icon, after all. image

danielhickman commented 7 years ago

My current half-booty setup is using a exporting the AI files at 256px and inputting it into a PNG to ICO converter and storing all the files in a hidden folder in my C:/ drive (could be released in a DLL if it's easier to use). Then I use that change icon and Winaero Tweaks to get this result: image

I still have a lot to do but MaterialOS is fairly abandoned while it has lots of potential even for my personal setup. I'm unsure if I released Eduardo Pratti's Windows icons but he made 13 icons for folders and such and I used a few other Android and Linux icons for my other folders.

wilkgr76 commented 7 years ago

For somewhat automised, perhaps something such as this could help? https://www.addictivetips.com/windows-tips/apply-custom-icon-packs-on-windows-with-one-click-using-7conifier/

It appears to be free.

crutchcorn commented 7 years ago

7conifier does not seem to be open source or standard. We'd like it to be one or the other (if not both) if remotely possible. It also seems to work in the same dangerous DLL replacement way [the only way that I personally know to automate this] that I have warned against

wilkgr76 commented 7 years ago

Good point.

wilkgr76 commented 7 years ago

If it is simply the start menu shortcuts and desktop shortcuts to replace, editing the LNK files would work, and is not as dangerous.

It could be based on something like this: https://stackoverflow.com/questions/6805881/modify-windows-shortcuts-using-python

I'll try that a bit later, and using Python allows for easy GUI addition. However, the issue is of course that it is impractical to ship Python or to require users to install Python.

EDIT: It could also potentially be done using SmallBasic, which does output .exe files.

wilkgr76 commented 7 years ago

I threw together a simple SmallBasic program that currently can read all shortcuts from C:\ProgramData\Microsoft\Windows\Start Menu\Programs, get the properties (such as target, hotkey, etc) and then write a new shortcut. For now, it's writing to a different location because I don't want to have duplicates of everything, but it could in theory then delete the old shortcut, or move it somewhere else for backup.

I am using the LitDev extension, and you can adjust the output_folder variable to control where it will (for now) copy the shortcuts. I don't have any alternate ICO files to test right now, otherwise I'd try that.

[code removed as updated code below]

The way I was thinking of is using the executable name, but without the file extension - i.e. naming the icon files something like word.ico. Using LDFile.GetFile will shorten it from C:\Programs\blah\word.exe to word, to which it is simple enough to append the .ico and set as the new shortcut.

wilkgr76 commented 7 years ago

Alright, I updated the code, now it will check for icons. If a custom ICO exists, it will use, else it will use the default. As you can see, it works! 🙌

image For now, I used icons from here: https://saviourmachine.deviantart.com/art/Windows-Icons-V1-49139616 as they were already ICO files.

wilkgr76 commented 7 years ago

Here's the version with a simple UI. Would you like the compiled version too?

image

Code:


' Get shortcuts
shortcuts = File.GetFiles("C:\ProgramData\Microsoft\Windows\Start Menu\Programs")
' Folder to put shortcuts
output_folder = "D:\materialos\new_shortcuts\"
' Location where icons are stored
icons = "D:\materialos\icons\"

GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontBold = "False"
GraphicsWindow.CanResize = "False"
GraphicsWindow.Title = "Apply MaterialOS"

applyButton = Controls.AddButton("Apply!",0,0)
Controls.SetSize(applyButton,GraphicsWindow.Width,25)
Controls.ButtonClicked = ApplyIcons

feedback = Controls.AddMultiLineTextBox(0,25)
Controls.SetSize(feedback,GraphicsWindow.Width,GraphicsWindow.Height-25)

Sub ApplyIcons
  For i = 1 To Array.GetItemCount(shortcuts)
    'TextWindow.WriteLine(shortcuts[i])
    'TextWindow.WriteLine(LDShell.LinkGetProperty(shortcuts[i],"Icon"))
    'TextWindow.WriteLine(LDShell.LinkGetProperty(shortcuts[i],"Target"))
    'TextWindow.WriteLine(LDShell.ShellLinkGet(shortcuts[i],"Icon"))

    oldlog = Controls.GetTextBoxText(feedback)

    Target = LDShell.ShellLinkGet(shortcuts[i],"Target")
    Args = LDShell.ShellLinkGet(shortcuts[i],"Args")
    Folder = LDShell.ShellLinkGet(shortcuts[i],"Folder")
    Desc = LDShell.ShellLinkGet(shortcuts[i],"Desc")
    Hotkey = LDShell.ShellLinkGet(shortcuts[i],"HotKey")
    Style = LDShell.ShellLinkGet(shortcuts[i],"Style")

    If LDFile.Exists(icons + LDFile.GetFile(Target) + ".ico") Then
      Icon = icons + LDFile.GetFile(Target) + ".ico"
      Controls.SetTextBoxText(feedback, oldlog + newLine + "Applied icon for " + LDFile.GetFile(shortcuts[i]))
    Else
      Icon = LDShell.ShellLinkGet(shortcuts[i],"Icon")
      Controls.SetTextBoxText(feedback, oldlog + newLine + "Keeping default icon for " + LDFile.GetFile(shortcuts[i]))
    EndIf

    'TextWindow.WriteLine(output_folder + LDFile.GetFile(shortcuts[i]) + ".lnk")
    LDShell.ShellLink(output_folder + LDFile.GetFile(shortcuts[i]) + ".lnk",Target)
    LDShell.ShellLinkSet(output_folder + LDFile.GetFile(shortcuts[i]) + ".lnk",Target,Args,Folder,Desc,Icon,Hotkey,Style)
  EndFor
EndSub

Controls.SetTextBoxText(feedback, "Click 'apply' to start!")
wilkgr76 commented 7 years ago

Now that I think about it, there are missing shortcuts. These are stored in %appdata%\Microsoft\Windows\Start Menu\Programs it seems. Guess I'll have to add them.

wilkgr76 commented 7 years ago

For some reason it fails with some shortcuts. Rather than recreating the shortcuts, it'll just copy those (as long as it doesn't use a custom icon.)

crutchcorn commented 7 years ago

@wilkgr76 While we could modify LNKs, I know that these are not universal. We are not able to theme system icons this way, are not able to keep up with the HUGE number of shortcuts someone could create, etc. Well outside of scope of this project.

THAT being said; it's clear you have an idea here that could easily work. If you were to, say, create an open source project with a GUI and such (something I wouldn't mind contributing to; and could) to keep up with these and applying packaged DLLs or a standard file format/package (something your project could create), we could support your project and advertise for it. ;) ;) ;) nudge nudge nudge

wilkgr76 commented 7 years ago

I will load the source up onto GitHub, and hopefully switch away from SmallBasic. At the moment, it isn't great, as it is relatively slow.

SB is good for prototyping, but I wouldn't want to use it for anything close to production! 😋

For the packaging, a simple ZIP file would work, and setting the icon name to the same as the executable - for example, the icon for powerpoint is called powerpnt.ico as the executable for powerpoint is called powerpnt.exe.

However, if I continue to link it as I have done previously, then I will need to extract these previously. I don't believe that this is an issue.

EDIT: I'm currently uploading my current version of the source. EDIT2: Uploaded. https://github.com/wilkgr76/windows_icon_applier

wilkgr76 commented 6 years ago

So, unfortunately, due to school, I don't really have much time. However, I am working on it in my spare time 😄