代码之家  ›  专栏  ›  技术社区  ›  Epaga Alex Reynolds

如何获取自己文件格式的文件以拥有自己的动态图标?

  •  9
  • Epaga Alex Reynolds  · 技术社区  · 17 年前

    我们的应用程序具有类似于OpenDocument文件格式的文件格式(请参见 http://en.wikipedia.org/wiki/OpenDocument )-即用清单文件、缩略图等压缩。

    我注意到OpenOffice文件在Windows和Linux中都有一个打开的Office文件的预览图像作为它们的图标。对于我们的文件,是否有一些方法可以做到这一点:例如,我想要一个基于internal thumbnail.png的动态图标?

    编辑1 哇,谢谢你的快速回答。 Thumbnailer 看起来很适合侏儒世界。Windows我会查看这些链接,谢谢。至于评论问题:通过编程或我们的安装程序。

    编辑2 哦,忘了麦克。在Mac上怎么样?(对不起,Mac爱好者们!)还有关于OpenOffice如何处理他们的Iconhandler内容的链接或信息吗?因为我们的链接或信息非常相似?

    9 回复  |  直到 12 年前
        1
  •  8
  •   Community Mohan Dere    8 年前

    窗户

    你需要的是 Icon Handler ,也称为缩略图处理程序。下面是一个写为 active x control .

    另一个资源是查找 Property Handlers 它还应该向您指出在Windows中正确处理动态元数据的最新和最好的方法。

    这些是 动态 解决方案-如果您只需要与所有文件关联的图标,则不需要它们-它们仅在您希望Windows资源管理器基于文件中的内容(而不仅仅是扩展名)显示图标时使用,并且当文件更改时,会更新图标以反映更改。它不必是文件本身的图像,缩略图处理程序也可以基于文件内容生成任何图像。

    属性处理程序更新其他元数据,如歌曲或视频长度,以便您可以使用Windows资源管理器支持的所有元数据。

    关于Mac支持, this page 说:“Mac和Windows操作系统有不同的方法来启用这种缩略图,在Mac操作系统的情况下,这种支持在不同版本之间是不一致的,因此(对于Adobe InDesign)没有追求这种支持。”

    操作系统X

    Mac OSX的图标由 Launch Services Database . 但是,它指的是注册应用程序处理的所有文件的静态图标文件(它不是基于扩展名的-每个文件都附加了元数据,以确定它所属的应用程序,尽管扩展名在元数据不存在时给出提示,例如从不同的操作系统或文件系统获取文件)。

    OSX中的动态图标功能似乎是由finder提供的,但是搜索并没有在这个方向上提供任何简单的指针。随着时间的推移,finder一直在变化,我明白了为什么这个目标很难击中…

    侏儒

    对于侏儒,你使用 thumbnailer . (谢谢) Dorward )

    这是您编写的一个非常简单的程序,它有3个命令行参数:

    • 输入文件名,用缩略图描述的文件(如果接受,则为URI)
    • 输出文件名,需要在其中写入PNG
    • 大小,以像素为单位的数字,表示您应该生成的最大方形图像大小(128-->128x128或更小)

    我希望所有的系统都这么简单。另一方面,它不支持动画和其他一些由更难在其他系统上实现的插件提供的功能。

    KDE

    我有点不确定,但有一些建议可以让你开始。首先,konkeror是一个文件管理器并显示图标——它支持一些内置类型的动态图标,但我不知道这些图标是硬编码的,还是可以编写的插件。退房 Embedded Components Tutorial 作为起点。

    有一个新的(ish?)特性(或计划特性…)称为等离子,与图标和图标功能有很大关系。退房 this announcment this initial implementation .

    您可能需要深入研究Konquerror的源代码,并检查它们是如何对文本文件和其他已经实现的文件执行此操作的。

    -亚当

        2
  •  4
  •   gamma    16 年前

    Mac OSX从10.5版开始

    有两种方法:

    1. 您的文档采用标准OSX捆绑格式,并且具有静态图像 这可以通过创建子文件夹QuickLook并将thumbnail/preview.png/tiff/jpg放入其中来完成。

    2. 其他一切 需要一个QuickLook生成器插件,该插件可以存储在/library/quicklook~/library/quicklook或yourapp.app/contents/library/quicklook文件夹中。

    此生成器用于动态创建缩略图和快速查看预览。Xcode为此提供了一个模板。模板生成所需的 美国国家标准委员会 必须实现的文件。如果你想写 对象C 代码必须重命名generateThumbnailForURL。 C 和GeneratePreviewForURL。 C 生成umbnailforurl。 和GeneratePreviewForURL。 (仔细阅读Apple Devel文档;)


    基于Zip容器的简单演示:

    您必须将cocoa.framework和foundation.framework添加到您的项目中。 在您的generatethumbnailforurl.c中(这部分是我头脑中的一部分-所以不能保证它是在盒子中工作的;):

    #include <Cocoa/Cocoa.h>
    #include <Foundation/Foundation.h>
    
    OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
    {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
      /* unzip the thumbnail and put it into an NSData object */
      // Create temporary path and writing handle for extraction
      NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingFormat: [NSString stringWithFormat: @"%.0f.%@" , [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"png"]];
      [[NSFileManager defaultManager] createFileAtPath: tmpPath contents: [NSData alloc] attributes:nil];
      NSFileHandle *writingHandle = [NSFileHandle fileHandleForWritingAtPath: tmpPath];
    
    
      // Use task to unzip - create command: /usr/bin/unzip -p <pathToFile> <fileToExtract>
      NSTask *unzipTask = [[NSTask alloc] init];
      [unzipTask setLaunchPath: @"/usr/bin/unzip"];
    
      // -p -> output to StandardOut, added File to extract, nil to terminate Array
      [unzipTask setArguments: [NSArray arrayWithObjects: @"-p", [(NSURL *) url path], @"Thumbnails/thumbnail.png", nil]];
    
      // redirect standardOut to writingHandle
      [unzipTask setStandardOutput: writingHandle];
    
      // Unzip - run task
      [unzipTask launch];
      [unzipTask waitUntilExit];
    
      // Read Image Data and remove File
      NSData *thumbnailData = [NSData dataWithContentsOfFile: tmpPath];
      [[NSFileManager defaultManager] removeFileAtPath: tmpPath handler:nil];
    
    
      if ( thumbnailData == nil || [thumbnailData length] == 0 ) {
         // Nothing Found. Don't care.
         [pool release];
         return noErr;
      }
    
      // That is the Size our image should have - create a dictionary too
      CGSize size = CGSizeMake(256, 256);
      NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
          [NSNumber numberWithInt:size.width],kQLPreviewPropertyWidthKey,
          [NSNumber numberWithInt:size.height],kQLPreviewPropertyHeightKey,
          nil];
    
      // Get CGContext for Thumbnail
      CGContextRef CGContext = QLThumbnailRequestCreateContext(thumbnail, size, TRUE, (CFDictionaryRef)properties);
      if(CGContext) {
         NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void *)CGContext flipped:size.width > size.height];
         if(context) {
            //These two lines of code are just good safe programming…
           [NSGraphicsContext saveGraphicsState];
           [NSGraphicsContext setCurrentContext:context];
    
           NSBitmapImageRep *thumbnailBitmap = [NSBitmapImageRep imageRepWithData:thumbnailData];
           [thumbnailBitmap draw];
    
           //This line sets the context back to what it was when we're done
           [NSGraphicsContext restoreGraphicsState];
        }
    
        // When we are done with our drawing code QLThumbnailRequestFlushContext() is called to flush the context
        QLThumbnailRequestFlushContext(thumbnail, CGContext);
    
        // Release the CGContext
        CFRelease(CGContext);
      }
    
      [pool release];
      return noErr;
    }
    

    幻灯片

    你也必须修改你的info.plist文件-当你打开它时,它有很多预先设置的字段。其中大多数都是自我解释的(或不必更改),但我必须添加以下结构(复制粘贴应该做-复制文本,进入plist编辑器,然后粘贴)。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <array>
       <dict>
         <key>UTTypeConformsTo</key>
         <array>
           <string>com.pkware.zip-archive</string>
         </array>
         <key>UTTypeDescription</key>
         <string>i-net Crystal-Clear Report File</string>
         <key>UTTypeIconName</key>
         <string>generic</string>
         <key>UTTypeIdentifier</key>
         <string>com.company.product</string>
         <key>UTTypeReferenceURL</key>
         <string>http://your-url.com</string>
         <key>UTTypeTagSpecification</key>
         <dict>
           <key>public.filename-extension</key>
             <array>
               <string>$fileEXT$</string>
             </array>
         </dict>
      </dict>
    </array>
    </plist>
    

    这将注册您的文件类型$fileext$并告诉系统您的文件类型是一个压缩格式类型。一个很好的参考,我在这里使用的是 QuickLook IPA Plugin from googlecode

        3
  •  2
  •   Fake Jim    17 年前

    在Windows中,您需要实现一个图标处理程序。我以前做过很多次,只要你了解COM的基础知识就不难了。

    见: http://msdn.microsoft.com/en-us/library/bb776857(VS.85).aspx

        4
  •  1
  •   Quentin    17 年前

    对于侏儒,你使用 thumbnailer .

        5
  •  0
  •   Paul Whelan    17 年前

    据我所知,这取决于操作系统,它将基于文件扩展名。

        6
  •  0
  •   Tom    17 年前

    对于Windows,请尝试以下操作:

    http://www.easydesksoftware.com/news/news12.htm

        7
  •  0
  •   pappes    17 年前

    可执行文件中的图标(可能是多个)作为“资源”。

    数据文件根据文件关联选取一个图标。

    如果你想要一个自定义的图标,每个文件就更难了。您要么太过愚弄操作系统,认为它是一个可执行文件,并将图标作为资源嵌入到文件中,要么在操作系统中进行深度链接,以覆盖默认的图标选择例程。

        8
  •  0
  •   TcKs    17 年前

    我认为,“自定义自己”图标在Windows中只能有PE文件。文件扩展名的所有其他图标都存储在Windows注册表中。

    对于PE文件的规范,您可以查看 An In-Depth Look into the Win32 Portable Executable File Format Peering Inside the PE: A Tour of the Win32 Portable Executable File Format .

    它在其他操作系统中是如何工作的,我不知道:/。

        9
  •  0
  •   Mark Ransom    17 年前

    我不知道Linux,但是对于Windows,您可以从这里开始: http://msdn.microsoft.com/en-us/library/bb774614.aspx

    编辑: 我认为这个界面是缩略图视图中显示的缩略图,而不是图标。抱歉浪费你的时间。