كيف يمكنني الحصول على أيقونة لجهاز تخزين في Mac OS X؟

StackOverflow https://stackoverflow.com/questions/580002

  •  06-09-2019
  •  | 
  •  

سؤال

لقد وجدت أجهزتي باستخدام IOServiceGetMatchingServices وحصل على قاموس العقار مثل هذا:

kernResult = IORegistryEntryCreateCFProperties(nextMedia,
                    (CFMutableDictionaryRef *)&props,
                                              kCFAllocatorDefault, 0);

من هذا القاموس يمكنني استخراج معلومات الرموز:

NSString *bId = [props valueForKeyPath:@"IOMediaIcon.CFBundleIdentifier"];
NSString *rFile = [props valueForKeyPath:@"IOMediaIcon.IOBundleResourceFile"];

أولئكان يعطيني هذا (كمثال):

com.apple.iokit.iostoragefamily (معرف الحزمة) الداخلية (ملف الموارد)

حاولت استخراج الرمز باستخدام هذه الطريقة:

NSBundle *bundleWithIcon = [NSBundle bundleWithIdentifier:bId];
NSString *iconPath = [bundleWithIcon pathForResource:rFile ofType:nil];

ولكن bundleWithIcon يكون nil.

هل هذه هي الطريقة الصحيحة للحصول على الرمز؟

أعتقد أنني لا بد لي من تحميل حزمة بطريقة أو بأخرى لتكون قادرة على تحميلها bundleWithIdentifier, ، كيف يمكنني أن أفعل هذا؟

ملاحظة: هناك سؤال آخر الذي (أعتقد) يحاول أن يسأل نفس الشيء، ولكن يسأل فقط حزم، وليس إذا كانت هذه هي الطريقة الصحيحة.

هل كانت مفيدة؟

المحلول 2

مؤخرا أجاب أندرو ميريك سؤال مماثل في القائمة البريدية DARWIN-DEV:

KextManagerCreateURLForBundleIdentifier()في <IOKit/kext/KextManager.h> قد يكون من الاستخدام، على الرغم من أنني أعتقد أنه يعمل فقط من أجل KXTS إما 1) محمل أو 2) في / S / L / E /. هنا هو Snow Leopard Headerdoc:

/*!
 * @function KextManagerCreateURLForBundleIdentifier
 * @abstract Create a URL locating a kext with a given bundle identifier.
 *
 * @param    allocator
 *           The allocator to use to allocate memory for the new object.
 *           Pass <code>NULL</code> or <code>kCFAllocatorDefault</code>
 *           to use the current default allocator.
 * @param    kextIdentifier
 *           The bundle identifier to look up.
 *
 * @result
 * A CFURLRef locating a kext with the requested bundle identifier.
 * Returns <code>NULL</code> if the kext cannot be found, or on error.
 *
 * @discussion
 * Kexts are looked up first by whether they are loaded, second by version.
 * Specifically, if <code>kextIdentifier</code> identifies a kext
 * that is currently loaded,
 * the returned URL will locate that kext if it's still present on disk.
 * If the requested kext is not loaded,
 * or if its bundle is not at the location it was originally loaded from,
 * the returned URL will locate the latest version of the desired kext,
 * if one can be found within the system extensions folder.
 * If no version of the kext can be found, <code>NULL</code> is returned.
 */
CFURLRef KextManagerCreateURLForBundleIdentifier(
    CFAllocatorRef allocator,
    CFStringRef    kextIdentifier);

لاحظ أنه قبل نمر الثلج، قد يعمل فقط من أجل KXTS IN / S / L / E؛ يوجد API، ولكن لم يكن هناك headerdoc وصف سلوكه.

بالنسبة لي هذا عمل جيدا حقا على نظام التشغيل Mac OS X 10.5.

نصائح أخرى

يمكنك استخدام NSWorkSpace.
الصورة الأولية هي 32 × 32، ولكن لديها تمثيلات للأحجام الأخرى وسوف على نطاق واسع

NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSImage * icon = [ws iconForFile:@"/Volumes/Whatever"];
NSLog(@"%@", [icon representations]); // see what sizes the icon has
icon.size = NSMakeSize(512, 512);

هذا قد يساعدك. (أو ربما لا) ...

عند اللعب مع الأمر "ioreg"، جئت إلى شيء ذكرني سؤالك، لذلك سأقوم بنشره:

حاول إصدار الأمر التالي:

ioreg -c IOMedia -x

والتي سوف تسفر عن فوضى كبيرة من الإخراج والتي تبدو مثل هذا:

  |     +-o IOBlockStorageDriver  <class IOBlockStorageDriver, registered, matched, active, busy 0, retain 7>
  |       +-o Apple read/write Media  <class IOMedia, registered, matched, active, busy 0, retain 9>
  |         | {
  |         |   "Removable" = Yes
  |         |   "BSD Unit" = 0x4
  |         |   "IOBusyInterest" = "IOCommand is not serializable"
  |         |   "BSD Minor" = 0xc
  |         |   "Ejectable" = Yes
  |   |         |   "BSD Name" = "disk4"
  |         |   "Leaf" = No
  |         |   "IOMediaIcon" = {"CFBundleIdentifier"="com.apple.iokit.IOStorageFamily","IOBundleResourceFile"="Removable.icns"}
  |         |   "Preferred Block Size" = 0x200
  |         |   "Whole" = Yes
  |         |   "Open" = Yes
  |         |   "Size" = 0x100000
  |         |   "Writable" = Yes
  |         |   "Content" = "Apple_partition_scheme"
  |         |   "IOGeneralInterest" = "IOCommand is not serializable"
  |         |   "Content Hint" = ""
  |         | }         |   "BSD Major" = 0xe

هذا كله يقودني إلى الاعتقاد (وبالتالي هنا يوصي به عمياء أن التحقيق) أنه إذا كنت تعاني من شجرة التسجيل IO مطابقة ضد "Iomedia"، فيمكنك الحصول على قواميس العقارات التي ستتضمن إدخال إدخال "Iomediaicon" الذي يبدو أنه نفسه مجموعة إعلامك بمعرف حزمة واسم ملف مورد.

لا يعني أن هذا سهل ... ولكن انظر إلى Firewire SDK. لكل رمز المثال، قد تحتاج ... في أي حال، ربما "أفضل" من المسارات الصلبة المملوءة مسبقا (والتي قد تختفي في إصدارات OS المستقبلية).

| ك

أولئكان يعطيني هذا (كمثال):

com.apple.iokit.iostoragefamily (معرف الحزمة) الداخلية (ملف الموارد)

حاولت استخراج الرمز باستخدام هذه الطريقة:

nsbundle * bundlewithicon = [nsbundle bundlewithidentifiertifier]؛ nsstring * iconpath = [pundlewithicon pathforresource: rfile oftype: nil]؛

ولكن bundleWithIcon يكون nil.

bundleWithIdentifier: يتطلب منك إنشاء مثيل NSBundle بالفعل للحصول على حزمة مع هذا المعرف؛ يبحث فقط عن مثيل تم إنشاؤه مسبقا. لذلك، ستحتاج إلى العثور على الحزمة في نظام الملفات وفكرته بواسطة اسم المسار. لحسن الحظ، يبدو أن لديك بالفعل الرابط للسؤال حول ذلك.

سيتم عرض وحدة تخزين بدون أيقونة مخصصة بأحد الأيقونات العامة لنظام التشغيل المسؤوليات التي ترميزها هنا. سيتم تخزين وحدة تخزين أيقونة مخصصة هذا الرمز على نظام الملفات الخاص به، وإذا لم يتم تركيبه، فابحث عن عملك بالكامل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top