Ticket #13952: 0001-Icon-O-Matic-convert-IOM-to-HVIF-RDef-Source-SVG-fro.patch

File 0001-Icon-O-Matic-convert-IOM-to-HVIF-RDef-Source-SVG-fro.patch, 5.3 KB (added by owenca, 6 years ago)

Replacing the previous patch.

  • src/apps/icon-o-matic/IconEditorApp.cpp

    From 0908b06f1c0c041da500bf2e413b55bf8ae45644 Mon Sep 17 00:00:00 2001
    From: Owen <owenca@users.noreply.github.com>
    Date: Thu, 11 Jan 2018 16:55:29 +0000
    Subject: [PATCH] Icon-O-Matic: convert IOM to HVIF/RDef/Source/SVG from
     command line
    
    Usage: Icon-O-Matic -[H|R|S|s] -o output_file IOM_file
    
    Returns: 0 if successful; nonzero otherwise
    
    Fixes #13952
    ---
     src/apps/icon-o-matic/IconEditorApp.cpp | 128 ++++++++++++++++++++++++++++++--
     src/apps/icon-o-matic/IconEditorApp.h   |   2 +
     src/apps/icon-o-matic/main.cpp          |   4 +-
     3 files changed, 125 insertions(+), 9 deletions(-)
    
    diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp
    index d667ce9..96f7483 100644
    a b  
    66
    77#include "IconEditorApp.h"
    88
     9#include "Document.h"
     10#include "FlatIconExporter.h"
     11#include "Icon.h"
     12#include "MessageImporter.h"
     13#include "RDefExporter.h"
     14#include "SimpleFileSaver.h"
     15#include "SourceExporter.h"
     16#include "SVGExporter.h"
     17
    918#include <new>
    1019#include <stdio.h>
    1120#include <string.h>
     
    3241#define B_TRANSLATION_CONTEXT "Icon-O-Matic-Main"
    3342
    3443
     44extern int exitCode;
     45
     46
    3547using std::nothrow;
    3648
    3749static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic";
    3850
    3951static const float kWindowOffset = 20;
    4052
     53static bool isCLI;
     54
    4155
    4256IconEditorApp::IconEditorApp()
    4357    :
    44     BApplication(kAppSig),
    45     fWindowCount(0),
    46     fLastWindowFrame(50, 50, 900, 750),
     58    BApplication(kAppSig)
     59{
     60}
    4761
    48     fOpenPanel(NULL),
    49     fSavePanel(NULL),
    5062
    51     fLastOpenPath(""),
    52     fLastSavePath(""),
    53     fLastExportPath("")
     63void
     64IconEditorApp::_Init()
    5465{
     66    fWindowCount = 0;
     67    fLastWindowFrame.Set(50, 50, 900, 750);
     68
     69    fOpenPanel = NULL;
     70    fSavePanel = NULL;
     71
     72    fLastOpenPath = "";
     73    fLastSavePath = "";
     74    fLastExportPath = "";
     75
    5576    // create file panels
    5677    BMessenger messenger(this, this);
    5778    BMessage message(B_REFS_RECEIVED);
    IconEditorApp::~IconEditorApp()  
    79100bool
    80101IconEditorApp::QuitRequested()
    81102{
     103    if (isCLI)
     104        return true;
     105
    82106    // Run the QuitRequested() hook in each window's own thread. Otherwise
    83107    // the BAlert which a window shows when an icon is not saved will not
    84108    // repaint the window. (BAlerts check which thread is running Go() and
    IconEditorApp::MessageReceived(BMessage* message)  
    202226void
    203227IconEditorApp::ReadyToRun()
    204228{
     229    if (isCLI)
     230        return;
     231
     232    _Init();
     233
    205234    // create main window
    206235    if (fWindowCount == 0)
    207236        _NewWindow()->Show();
    IconEditorApp::RefsReceived(BMessage* message)  
    248277}
    249278
    250279
     280static status_t
     281ConvertIcon(const char* from, const char* to, const char* format)
     282{
     283    uint32 exportMode;
     284    if (strcmp(format, "-H") == 0)
     285        exportMode = EXPORT_MODE_FLAT_ICON;
     286    else if (strcmp(format, "-R") == 0)
     287        exportMode = EXPORT_MODE_ICON_RDEF;
     288    else if (strcmp(format, "-S") == 0)
     289        exportMode = EXPORT_MODE_ICON_SOURCE;
     290    else if (strcmp(format, "-s") == 0)
     291        exportMode = EXPORT_MODE_SVG;
     292    else
     293        return B_ERROR;
     294
     295    entry_ref ref;
     296    status_t ret = get_ref_for_path(from, &ref);
     297    if (ret != B_OK)
     298        return ret;
     299
     300    BFile file(&ref, B_READ_ONLY);
     301    ret = file.InitCheck();
     302    if (ret < B_OK)
     303        return ret;
     304
     305    ret = get_ref_for_path(to, &ref);
     306    if (ret != B_OK)
     307        return ret;
     308
     309    Icon* icon = new (nothrow) Icon();
     310    if (icon == NULL)
     311        return B_ERROR;
     312
     313    MessageImporter msgImporter;
     314    ret = msgImporter.Import(icon, &file);
     315    if (ret < B_OK) {
     316        delete icon;
     317        return ret;
     318    }
     319
     320    DocumentSaver* saver = NULL;
     321    switch (exportMode) {
     322        case EXPORT_MODE_FLAT_ICON:
     323            saver = new SimpleFileSaver(new FlatIconExporter(), ref);
     324            break;
     325        case EXPORT_MODE_ICON_RDEF:
     326            saver = new SimpleFileSaver(new RDefExporter(), ref);
     327            break;
     328        case EXPORT_MODE_ICON_SOURCE:
     329            saver = new SimpleFileSaver(new SourceExporter(), ref);
     330            break;
     331        case EXPORT_MODE_SVG:
     332            saver = new SimpleFileSaver(new SVGExporter(), ref);
     333            break;
     334    }
     335
     336    if (saver == NULL) {
     337        delete icon;
     338        return B_ERROR;
     339    }
     340
     341    Document* document = new Document(to);
     342    if (document == NULL) {
     343        delete icon;
     344        return B_ERROR;
     345    }
     346
     347    document->SetIcon(icon);
     348    document->SetExportSaver(saver);
     349    saver->Save(document);
     350
     351    return B_OK;
     352}
     353
     354
    251355void
    252356IconEditorApp::ArgvReceived(int32 argc, char** argv)
    253357{
    254358    if (argc < 2)
    255359        return;
    256360
     361    // Usage: Icon-O-Matic -[H|R|S|s] -o output_file IOM_file
     362    if (argc == 5 && strcmp(argv[2], "-o") == 0) {
     363        isCLI = true;
     364        exitCode = ConvertIcon(argv[4], argv[3], argv[1]);
     365        PostMessage(B_QUIT_REQUESTED);
     366        return;
     367    }
     368
    257369    entry_ref ref;
    258370
    259371    for (int32 i = 1; i < argc; i++) {
  • src/apps/icon-o-matic/IconEditorApp.h

    diff --git a/src/apps/icon-o-matic/IconEditorApp.h b/src/apps/icon-o-matic/IconEditorApp.h
    index 44df93a..f6ecc88 100644
    a b public:  
    6060    // IconEditorApp
    6161
    6262private:
     63            void                _Init();
     64
    6365            MainWindow*         _NewWindow();
    6466
    6567            void                _SyncPanels(BFilePanel* from,
  • src/apps/icon-o-matic/main.cpp

    diff --git a/src/apps/icon-o-matic/main.cpp b/src/apps/icon-o-matic/main.cpp
    index c7b6492..0f997b3 100644
    a b  
    88
    99#include "IconEditorApp.h"
    1010
     11int exitCode;
     12
    1113int
    1214main(int argc, char** argv)
    1315{
    main(int argc, char** argv)  
    1618
    1719    delete app;
    1820
    19     return 0;
     21    return exitCode;
    2022}