Преглед на файлове

Windows: .lynx file association for the current user with its own project-file icon

Ka1-S преди 1 месец
родител
ревизия
e6cf0cc3bf
променени са 8 файла, в които са добавени 100 реда и са изтрити 1 реда
  1. 1 0
      CMakeLists.txt
  2. 1 0
      resources/LYNX.rc
  3. BIN
      resources/LYNX_doc.ico
  4. 1 1
      scripts/build-windows-zig.sh
  5. 2 0
      src/Main.cpp
  6. 36 0
      src/platform/FileTypes.cpp
  7. 9 0
      src/platform/FileTypes.h
  8. 50 0
      tools/make_doc_icon.py

+ 1 - 0
CMakeLists.txt

@@ -91,6 +91,7 @@ if(LYNX_BUILD_APP)
 
     target_sources(LYNX PRIVATE
         src/Main.cpp
+        src/platform/FileTypes.cpp
         src/engine/AudioEngine.cpp
         src/engine/ChannelRackProcessor.cpp
         src/engine/Metronome.cpp

+ 1 - 0
resources/LYNX.rc

@@ -1,3 +1,4 @@
 #include <winuser.h>
 CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "LYNX.manifest"
 1 ICON "LYNX.ico"
+2 ICON "LYNX_doc.ico"

BIN
resources/LYNX_doc.ico


+ 1 - 1
scripts/build-windows-zig.sh

@@ -76,7 +76,7 @@ APP_SOURCES=(src/Main.cpp
              src/ui/MainComponent.cpp src/ui/ChannelRackComponent.cpp src/ui/PianoRollComponent.cpp src/ui/PlaylistComponent.cpp src/ui/MixerComponent.cpp src/ui/PluginWindow.cpp src/ui/WindowOwner.cpp src/ui/ParametricEqEditor.cpp src/ui/ExportDialog.cpp src/ui/AutomationUi.cpp src/ui/ChannelSettings.cpp src/ui/BrowserComponent.cpp src/ui/Theme.cpp src/ui/Icons.cpp src/ui/I18n.cpp src/ui/EditorTools.cpp
              src/core/Song.cpp src/core/Scheduler.cpp src/core/Instruments.cpp src/core/RackRenderer.cpp
              src/core/FlpImport.cpp src/core/Effects.cpp src/core/NoteEdit.cpp src/core/Recorder.cpp src/core/Pdc.cpp src/core/WorkerPool.cpp src/core/TimeStretch.cpp src/core/Arpeggiator.cpp src/core/SynthPresets.cpp src/core/Slicer.cpp src/core/Templates.cpp src/core/FlWrapper.cpp src/core/FlEffects.cpp src/core/Effector.cpp src/core/VintagePhaser.cpp src/core/Vocodex.cpp src/core/FlSamplers.cpp src/core/FlSynths.cpp src/core/FlSytrus.cpp src/core/FlGenerators.cpp src/core/PhysicalModels.cpp src/core/DrumSynthLive.cpp src/core/SytrusEngine.cpp src/core/Harmless.cpp src/core/HarmlessFx.cpp src/core/Harmor.cpp src/core/FlPatcher.cpp src/core/Inflate.cpp src/core/WavPack.cpp src/flp/Flp.cpp
-             src/platform/MingwFixes.cpp)
+             src/platform/MingwFixes.cpp src/platform/FileTypes.cpp)
 
 # workflow shell: core (key map, workspace layout, rack operations) and UI (workspace desktop, control contract)
 APP_SOURCES+=(src/core/KeyMap.cpp src/core/Workspace.cpp src/core/RackOps.cpp src/ui/Workspace.cpp src/ui/ValueControl.cpp src/ui/Dialogs.cpp)

+ 2 - 0
src/Main.cpp

@@ -11,6 +11,7 @@
 #include "engine/ProjectFile.h"
 #include "engine/SampleLibrary.h"
 #include "engine/Text.h"
+#include "platform/FileTypes.h"
 #include "ui/AutomationUi.h"
 #include "ui/ChannelSettings.h"
 #include "ui/Dialogs.h"
@@ -302,6 +303,7 @@ public:
 
         juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
         startupOptions = lynx::StartupOptions::load();
+        lynx::registerFileTypes();
         // Double-clicking a .lynx/.flp opens LYNX with the file as an argument.
         if (args.size() > 0 && juce::File::isAbsolutePath (args[0].unquoted()))
             fileToOpen = juce::File (args[0].unquoted());

+ 36 - 0
src/platform/FileTypes.cpp

@@ -0,0 +1,36 @@
+#include "platform/FileTypes.h"
+
+#include <juce_core/juce_core.h>
+
+#if JUCE_WINDOWS
+ #include <windows.h>
+ #include <shlobj.h>
+#endif
+
+namespace lynx
+{
+void registerFileTypes()
+{
+   #if JUCE_WINDOWS
+    using juce::WindowsRegistry;
+    const auto exe = juce::File::getSpecialLocation (juce::File::currentExecutableFile).getFullPathName();
+    const juce::String classes = "HKEY_CURRENT_USER\\Software\\Classes\\";
+    const juce::String progId = "LYNX.Project";
+    const auto command = "\"" + exe + "\" \"%1\"";
+    const auto icon = "\"" + exe + "\",-2"; // resource id 2 in resources/LYNX.rc: the project-file icon
+
+    if (WindowsRegistry::getValue (classes + ".lynx\\") == progId
+        && WindowsRegistry::getValue (classes + progId + "\\shell\\open\\command\\") == command
+        && WindowsRegistry::getValue (classes + progId + "\\DefaultIcon\\") == icon)
+        return;
+
+    WindowsRegistry::setValue (classes + ".lynx\\", progId);
+    WindowsRegistry::setValue (classes + ".lynx\\Content Type", juce::String ("application/x-lynx-project"));
+    WindowsRegistry::setValue (classes + progId + "\\", juce::String ("LYNX Project"));
+    WindowsRegistry::setValue (classes + progId + "\\DefaultIcon\\", icon);
+    WindowsRegistry::setValue (classes + progId + "\\shell\\open\\command\\", command);
+    // Explorer caches icons per type: tell it the association changed
+    SHChangeNotify (SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
+   #endif
+}
+} // namespace lynx

+ 9 - 0
src/platform/FileTypes.h

@@ -0,0 +1,9 @@
+#pragma once
+
+namespace lynx
+{
+// Registers .lynx project files with Windows for the current user (no admin rights): double-click opens them in this
+// LYNX.exe and Explorer shows LYNX's project icon. Rewrites the entries only when they point somewhere else, so a
+// moved or updated exe takes the association over. Does nothing on other platforms.
+void registerFileTypes();
+} // namespace lynx

+ 50 - 0
tools/make_doc_icon.py

@@ -0,0 +1,50 @@
+# Generates the LYNX project-file icon (a dark page with a folded corner, a red band and the LYNX badge).
+# Usage: python3 tools/make_doc_icon.py resources/lynx_icon_256.png resources/LYNX_doc.ico [preview.png]
+import sys
+from PIL import Image, ImageDraw, ImageFilter
+
+S = 1024
+badge = Image.open(sys.argv[1]).convert("RGBA")
+
+page = Image.new("RGBA", (S, S), (0, 0, 0, 0))
+left, right, top, bottom = 150, 874, 40, 984
+fold = 230
+outline = [(left, top), (right - fold, top), (right, top + fold), (right, bottom), (left, bottom)]
+
+# soft shadow under the page
+shadow = Image.new("RGBA", (S, S), (0, 0, 0, 0))
+ImageDraw.Draw(shadow).polygon([(x + 14, y + 20) for x, y in outline], fill=(0, 0, 0, 120))
+page = Image.alpha_composite(page, shadow.filter(ImageFilter.GaussianBlur(22)))
+
+body = Image.new("RGBA", (S, S), (0, 0, 0, 0))
+d = ImageDraw.Draw(body)
+d.polygon(outline, fill=(38, 38, 43, 255))
+# vertical sheen: lighter at the top
+sheen = Image.linear_gradient("L").resize((S, S)).point(lambda v: int(40 * (1 - v / 255)))
+light = Image.new("RGBA", (S, S), (255, 255, 255, 0))
+light.putalpha(sheen)
+mask = Image.new("L", (S, S), 0)
+ImageDraw.Draw(mask).polygon(outline, fill=255)
+light.putalpha(Image.composite(light.getchannel("A"), Image.new("L", (S, S), 0), mask))
+body = Image.alpha_composite(body, light)
+d = ImageDraw.Draw(body)
+# red band at the bottom (the accent colour)
+d.rectangle((left, bottom - 150, right, bottom), fill=(214, 40, 40, 255))
+d.rectangle((left, bottom - 150, right, bottom - 138), fill=(240, 80, 70, 255))
+# folded corner
+d.polygon([(right - fold, top), (right - fold, top + fold), (right, top + fold)], fill=(78, 78, 86, 255))
+d.line([(right - fold, top), (right, top + fold)], fill=(20, 20, 24, 255), width=6)
+# thin border
+d.line(outline + [outline[0]], fill=(90, 90, 98, 255), width=8, joint="curve")
+page = Image.alpha_composite(page, body)
+
+# the LYNX badge in the middle of the page
+size = 560
+b = badge.resize((size, size), Image.LANCZOS)
+page.alpha_composite(b, ((left + right - size) // 2, top + fold - 40))
+
+sizes = [16, 20, 24, 32, 40, 48, 64, 96, 128, 256]
+page.save(sys.argv[2], format="ICO", sizes=[(s, s) for s in sizes])
+if len(sys.argv) > 3:
+    page.resize((256, 256), Image.LANCZOS).save(sys.argv[3])
+print("ok")