Icons display improvements? - Page 2

Icons display improvements?

Requests for features in the spring code.

Moderator: Moderators

User avatar
NTG
Posts: 23
Joined: 15 Nov 2008, 12:49

Re: Icons display improvements?

Post by NTG »

CarRepairer wrote:Well thank you for coming up with the idea and working on it. What I was hinting at was that it would be more useful for lobby clients to handle the management of maps and mods, but it couldn't hurt to have this too. It would certainly help in some scenarios.
Well, I can't wait for lobby with 'Delete' button and some other management options :P

As for now I've managed to find proper thumbnail interfaces (IThumbnailProvider for Vista and 7 or IExtractImage for 2000/ME, XP, Vista, not sure about 7) and Vista support interfaces IInitializeWithFile, IInitializeWithStream, IInitializeWithItem in Vista and 7. So far, not so bad - I've managed to make custom previews using Stream as input but:
  • I have some problems using IInitializeWithFile (would be better to communicate with unitsync) with IThumbnailProvider - can't have both of interfaces working.
  • I got some problems loading unmanaged code libraries (as unitsync.dll - can't locate after compiling). Never tried to do it before, any ideas?
  • Can't find any way to get any mod pic.
Next time I'll have some more free time (middle of January or February) I'm going to add some debug to find out what's going on.

Below easy code that demonstrates how to use interfaces:

Code: Select all

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;

namespace Thumbnailer{

    [ComVisible(true), ClassInterface(ClassInterfaceType.None)]
    [ProgId("Cogwheel.StateThumbnailProvider"), Guid("53a13663-b80b-4ab5-9c61-9d0d05ce389a")]
    public class ThumbnailProvider : IThumbnailProvider, IInitializeWithStream{
        public void Initialize(IStream stream, int grfMode){}

        public void GetThumbnail(int squareLength, out IntPtr hBitmap, out WTS_ALPHATYPE bitmapType){
            using (var Thumbnail = new Bitmap(squareLength, squareLength)){
                using (var G = Graphics.FromImage(Thumbnail)) G.Clear(Color.Red);
                hBitmap = Thumbnail.GetHbitmap();}
            bitmapType = WTS_ALPHATYPE.WTSAT_UNKNOWN;}
    }

    public enum WTS_ALPHATYPE{
        WTSAT_UNKNOWN = 0,
        WTSAT_RGB = 1,
        WTSAT_ARGB = 2
    }

    [ComVisible(true), Guid("e357fccd-a995-4576-b01f-234630154e96"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IThumbnailProvider{
        void GetThumbnail(int cx, out IntPtr hBitmap, out WTS_ALPHATYPE bitmapType);
    }

    [ComVisible(true), Guid("b824b49d-22ac-4161-ac8a-9916e8fa3f7f"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IInitializeWithStream{
        void Initialize(IStream stream, int grfMode);
    }
}

Code: Select all

[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsIUnknown, Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")]
interface IInitializeWithFile{
    void Initialize([MarshalAs(UnmanagedType.LPWStr)] string pszFilePath, uint grfMode);}
If problems with unitsync are gone then I guess it should be:

Code: Select all

[DllImport("unitsync.dll")]
static extern IntPtr GetMinimap(StringBuilder filename, int miplevel);
or similar marshalling. As I said I never used that before... Then it's the matter of getting minimap (can't find any method to get any mod pic):

Code: Select all

// int squareLength provided as GetThumbnail() parameter
Bitmap b = new Bitmap(squareLength, squareLength, 2, System.Drawing.Imaging.PixelFormat.Format16bppRgb565, GetMinimap(...));
and passing it to out value. And if it's work, should be fine then :)

To register component you need to update registry (hope haven't forgotten anything):

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\spring.sdz_archive\shellex\{e357fccd-a995-4576-b01f-234630154e96}]
@="{53a13663-b80b-4ab5-9c61-9d0d05ce389a}"
[HKEY_CLASSES_ROOT\spring.sd7_archive\shellex\{e357fccd-a995-4576-b01f-234630154e96}]
@="{53a13663-b80b-4ab5-9c61-9d0d05ce389a}"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]
"{53a13663-b80b-4ab5-9c61-9d0d05ce389a}"="anything you want as description :)"
and run a command in dir you have new DLL:

Code: Select all

%windir%\Microsoft.NET\Framework\v2.0.50727\RegAsm /codebase Thumbnailer.dll
I guess registry + RegAsm calling should have installer ;)


If anybody have got any ideas how to fix problems I encountered - it would be awesome for some feedback before I get to work again - I'm not very skilled with C# + Windows interfaces + Spring interfaces.

References:
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Icons display improvements?

Post by Tobi »

What is/are the problem(s) with unitsync?

EDIT: If it's just locating it, aren't there other tools that do this already in .NET? Otherwise maybe location is guessable from registry entries..
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Icons display improvements?

Post by BrainDamage »

Can't find any way to get any mod pic.
there is none inside the archive afaik, only unit pics
Post Reply

Return to “Feature Requests”