// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:43:15
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/app/FlashGeneratorPreview

package com.macromedia.generator.app;

import com.macromedia.generator.api.Serial;
import com.macromedia.generator.platform.Mac;
import java.io.*;
import java.util.Vector;

// Referenced classes of package com.macromedia.generator.app:
//            FlashGeneratorApp

public class FlashGeneratorPreview extends FlashGeneratorApp
{

    protected FlashGeneratorPreview()
    {
    }

    public static void main(String args[])
    {
        FlashGeneratorPreview flashgeneratorpreview = new FlashGeneratorPreview();
        flashgeneratorpreview.isPreviewMode = true;
        flashgeneratorpreview.init();
        try
        {
            if(flashgeneratorpreview.processArgs(args))
                flashgeneratorpreview.processTemplate();
        }
        catch(Exception exception)
        {
            if(flashgeneratorpreview.logWriter == null)
                exception.printStackTrace();
            else
                exception.printStackTrace(flashgeneratorpreview.logWriter);
        }
        catch(Error error)
        {
            if(flashgeneratorpreview.logWriter == null)
                error.printStackTrace();
            else
                error.printStackTrace(flashgeneratorpreview.logWriter);
        }
        try
        {
            flashgeneratorpreview.finalize();
        }
        catch(Throwable _ex) { }
        flashgeneratorpreview = null;
    }

    protected boolean processArgs(String as[])
    {
        Mac mac = Mac.getMac();
        params = new Vector();
        if(as.length < 1)
        {
            log(getResString("InvalidArgs"));
            return false;
        }
        for(int i = 0; i < as.length; i++)
        {
            String s = as[i].toLowerCase();
            if(s.equals("-h"))
            {
                log(getResString("InvalidArgs"));
                return false;
            }
            if(s.equals("-f") || s.equals("-swf"))
            {
                if(i + 1 < as.length)
                {
                    flashPath = as[++i];
                    if(mac != null)
                        flashPath = mac.makeJavaPretty(flashPath);
                } else
                {
                    log(getResString("DashFRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-g") || s.equals("-gif"))
            {
                if(i + 1 < as.length)
                {
                    gifPath = as[++i];
                    if(mac != null)
                        gifPath = mac.makeJavaPretty(gifPath);
                } else
                {
                    log(getResString("DashGRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-l"))
            {
                if(i + 1 < as.length)
                {
                    logPath = as[++i];
                    if(mac != null)
                        logPath = mac.makeJavaPretty(logPath);
                    try
                    {
                        File file = new File(logPath);
                        logWriter = new PrintWriter(new FileOutputStream(file));
                        if(mac != null)
                            mac.setTypeAndCreator(file, "TEXT", "ttxt");
                    }
                    catch(Exception _ex)
                    {
                        System.err.println(getResString("LogFileInvalid") + logPath);
                    }
                    logOpened = true;
                } else
                {
                    log(getResString("DashLRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-c"))
            {
                if(i + 1 < as.length)
                {
                    String as1[] = new String[64];
                    int k = 0;
                    String s1 = as[++i];
                    boolean flag1 = false;
                    StringBuffer stringbuffer = new StringBuffer();
                    boolean flag3 = false;
                    int j1 = 0;
                    s1.trim();
                    while(j1 < s1.length()) 
                        if(s1.charAt(j1) == ' ')
                        {
                            if(flag3)
                            {
                                if(!flag1)
                                {
                                    as1[++k - 1] = stringbuffer.toString();
                                    flag3 = false;
                                    flag1 = false;
                                    stringbuffer.setLength(0);
                                    j1++;
                                } else
                                {
                                    stringbuffer.append(s1.charAt(j1));
                                    j1++;
                                }
                            } else
                            {
                                j1++;
                            }
                        } else
                        if(s1.charAt(j1) == '4')
                        {
                            if(flag1)
                            {
                                stringbuffer.append(s1.charAt(j1));
                                as1[++k - 1] = stringbuffer.toString();
                                stringbuffer.setLength(0);
                                flag3 = false;
                                flag1 = false;
                                j1++;
                            } else
                            if(!flag3)
                            {
                                stringbuffer.append(s1.charAt(j1));
                                flag3 = true;
                                flag1 = true;
                                j1++;
                            } else
                            {
                                stringbuffer.append(s1.charAt(j1));
                                j1++;
                            }
                        } else
                        if(s1.charAt(j1) == '\222')
                        {
                            if(j1 + 1 < s1.length())
                            {
                                stringbuffer.append(s1.charAt(j1 + 1));
                                j1 += 2;
                                if(!flag3)
                                    flag3 = true;
                            }
                        } else
                        {
                            stringbuffer.append(s1.charAt(j1));
                            j1++;
                            flag3 = true;
                        }
                    if(stringbuffer.length() > 0)
                        as1[++k - 1] = stringbuffer.toString();
                    for(int k1 = 0; k1 < k; k1++)
                    {
                        String s3 = as1[k1].toLowerCase();
                        if(s3.equals("-g") || s3.equals("-G"))
                        {
                            if(k1 + 1 < k)
                            {
                                gifPath = as1[++k1];
                                if(mac != null)
                                    gifPath = mac.makeJavaPretty(gifPath);
                            } else
                            {
                                log(getResString("DashGRequiresArg"));
                                return false;
                            }
                        } else
                        if(s3.equals("-p") || s3.equals("-param"))
                        {
                            if(k1 + 2 < k)
                            {
                                boolean flag5 = false;
                                String as3[] = new String[2];
                                as3[0] = as1[k1 + 1];
                                as3[1] = as1[k1 + 2];
                                if(as3[0].startsWith("-"))
                                {
                                    if(as3[0].equals("-p") || as3[0].equals("-param") || as3[0].equals("-png") || as3[0].equals("-jpg") || as3[0].equals("-qtm") || as3[0].equals("-g") || as3[0].equals("-gif"))
                                        log(getResString("InvalidNumPArgs"));
                                    else
                                    if(as3[1].startsWith("-"))
                                    {
                                        if(as3[1].equals("-p") || as3[1].equals("-param") || as3[1].equals("-png") || as3[1].equals("-jpg") || as3[1].equals("-qtm") || as3[1].equals("-g") || as3[1].equals("-gif"))
                                        {
                                            log(getResString("InvalidNumPArgs"));
                                            k1++;
                                        } else
                                        {
                                            flag5 = true;
                                        }
                                    } else
                                    {
                                        flag5 = true;
                                    }
                                } else
                                if(as3[1].startsWith("-"))
                                {
                                    if(as3[1].equals("-p") || as3[1].equals("-param") || as3[1].equals("-png") || as3[1].equals("-jpg") || as3[1].equals("-qtm") || as3[1].equals("-g") || as3[1].equals("-gif"))
                                    {
                                        log(getResString("InvalidNumPArgs"));
                                        k1++;
                                    } else
                                    {
                                        flag5 = true;
                                    }
                                } else
                                {
                                    flag5 = true;
                                }
                                if(flag5)
                                {
                                    params.addElement(as3);
                                    k1 += 2;
                                    int l1 = 1;
                                    if(k1 + l1 < k)
                                    {
                                        boolean flag6 = false;
                                        for(boolean flag7 = false; k1 + l1 < k && !flag7;)
                                        {
                                            String s4 = as1[k1 + l1];
                                            if(s4.startsWith("-"))
                                            {
                                                flag7 = true;
                                            } else
                                            {
                                                flag6 = true;
                                                l1++;
                                            }
                                        }

                                        if(flag6)
                                        {
                                            k1 += l1 - 1;
                                            log(getResString("TooManyPArgs"));
                                        }
                                    }
                                }
                            } else
                            {
                                log(getResString("InvalidNumPArgs"));
                            }
                        } else
                        if(s3.equals("-jpg"))
                        {
                            if(k1 + 1 < k)
                            {
                                jpegPath = as1[k1 + 1];
                                if(mac != null)
                                    jpegPath = mac.makeJavaPretty(jpegPath);
                                k1++;
                            } else
                            {
                                log(getResString("DashGRequiresArg"));
                                return false;
                            }
                        } else
                        if(s3.equals("-qtm"))
                        {
                            if(k1 + 1 < k)
                            {
                                QTMPath = as1[k1 + 1];
                                if(mac != null)
                                    QTMPath = mac.makeJavaPretty(QTMPath);
                                k1++;
                            } else
                            {
                                log(getResString("DashGRequiresArg"));
                                return false;
                            }
                        } else
                        if(s3.equals("-png"))
                            if(k1 + 1 < k)
                            {
                                pngPath = as1[k1 + 1];
                                if(mac != null)
                                    pngPath = mac.makeJavaPretty(pngPath);
                                k1++;
                            } else
                            {
                                log(getResString("DashGRequiresArg"));
                                return false;
                            }
                    }

                } else
                {
                    log(getResString("DashDRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-d"))
            {
                if(i + 1 < as.length)
                {
                    try
                    {
                        logLevel = Integer.valueOf(as[++i]).intValue();
                    }
                    catch(NumberFormatException _ex)
                    {
                        logLevel = -1;
                    }
                    if(logLevel < 0 || logLevel > 3)
                    {
                        log(getResString("InvalidDashDArg"));
                        return false;
                    }
                } else
                {
                    log(getResString("DashDRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-p") || s.equals("-param"))
            {
                if(i + 2 < as.length)
                {
                    boolean flag = false;
                    String as2[] = new String[2];
                    as2[0] = as[i + 1];
                    as2[1] = as[i + 2];
                    if(as2[0].startsWith("-"))
                    {
                        if(as2[0].equals("-p") || as2[0].equals("-param") || as2[0].equals("-png") || as2[0].equals("-jpg") || as2[0].equals("-g") || as2[0].equals("-gif") || as2[0].equals("-qtm"))
                            log(getResString("InvalidNumPArgs"));
                        else
                        if(as2[1].startsWith("-"))
                        {
                            if(as2[1].equals("-p") || as2[1].equals("-param") || as2[1].equals("-png") || as2[1].equals("-jpg") || as2[1].equals("-qtm") || as2[1].equals("-g") || as2[1].equals("-gif"))
                            {
                                log(getResString("InvalidNumPArgs"));
                                i++;
                            } else
                            {
                                flag = true;
                            }
                        } else
                        {
                            flag = true;
                        }
                    } else
                    if(as2[1].startsWith("-"))
                    {
                        if(as2[1].equals("-p") || as2[1].equals("-param") || as2[1].equals("-png") || as2[1].equals("-jpg") || as2[1].equals("-qtm") || as2[1].equals("-g") || as2[1].equals("-gif"))
                        {
                            log(getResString("InvalidNumPArgs"));
                            i++;
                        } else
                        {
                            flag = true;
                        }
                    } else
                    {
                        flag = true;
                    }
                    if(flag)
                    {
                        params.addElement(as2);
                        i += 2;
                        int i1 = 1;
                        if(i + i1 < as.length)
                        {
                            boolean flag2 = false;
                            for(boolean flag4 = false; i + i1 < as.length && !flag4;)
                            {
                                String s2 = as[i + i1];
                                if(s2.startsWith("-"))
                                {
                                    flag4 = true;
                                } else
                                {
                                    flag2 = true;
                                    i1++;
                                }
                            }

                            if(flag2)
                            {
                                i += i1 - 1;
                                log(getResString("TooManyPArgs"));
                            }
                        }
                    }
                } else
                {
                    log(getResString("InvalidNumPArgs"));
                }
            } else
            if(s.equals("-t"))
            {
                if(i + 1 < as.length)
                    if(inputPath == null)
                    {
                        inputPath = as[++i];
                        if(mac != null)
                            inputPath = mac.makeJavaPretty(inputPath);
                    } else
                    {
                        log(getResString("MultipleInputFiles") + as[i]);
                        return false;
                    }
            } else
            if(s.endsWith(".swf") || s.endsWith(".swt"))
            {
                if(inputPath == null)
                {
                    inputPath = as[i];
                    if(mac != null)
                        inputPath = mac.makeJavaPretty(inputPath);
                } else
                {
                    log(getResString("MultipleInputFiles") + as[i]);
                    return false;
                }
            } else
            if(s.equals("-jpg"))
            {
                if(i + 1 < as.length)
                {
                    jpegPath = as[++i];
                    if(mac != null)
                        jpegPath = mac.makeJavaPretty(jpegPath);
                } else
                {
                    log(getResString("DashGRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-qtm"))
            {
                if(i + 1 < as.length)
                {
                    QTMPath = as[++i];
                    if(mac != null)
                        QTMPath = mac.makeJavaPretty(QTMPath);
                } else
                {
                    log(getResString("DashGRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-png"))
            {
                if(i + 1 < as.length)
                {
                    pngPath = as[++i];
                    if(mac != null)
                        pngPath = mac.makeJavaPretty(pngPath);
                } else
                {
                    log(getResString("DashGRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-xwin32"))
            {
                if(i + 1 < as.length)
                {
                    projectorWPath = as[++i];
                    if(mac != null)
                        projectorWPath = mac.makeJavaPretty(projectorWPath);
                } else
                {
                    log(getResString("DashWin32RequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-xmacppc"))
            {
                if(i + 1 < as.length)
                {
                    projectorMPPCPath = as[++i];
                    if(mac != null)
                        projectorMPPCPath = mac.makeJavaPretty(projectorMPPCPath);
                } else
                {
                    log(getResString("DashWinPpcRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-embed"))
            {
                if(i + 1 < as.length)
                {
                    embeddedString = as[++i];
                } else
                {
                    log(getResString("DashEmbedRequiresArg"));
                    return false;
                }
            } else
            if(s.equals("-defaultsize"))
            {
                if(i + 2 < as.length)
                {
                    try
                    {
                        defaultWidth = Integer.valueOf(as[++i]).intValue();
                        defaultHeight = Integer.valueOf(as[++i]).intValue();
                    }
                    catch(NumberFormatException _ex)
                    {
                        defaultWidth = -1;
                        defaultHeight = -1;
                    }
                    if(defaultWidth <= 0 || defaultHeight <= 0)
                    {
                        log(getResString("DashDefaultSizeInvalidArg"));
                        usage(false);
                        return false;
                    }
                } else
                {
                    log(getResString("DashDefaultSizeRequiresArg"));
                    usage(false);
                    return false;
                }
            } else
            if(s.equalsIgnoreCase("-exactFit"))
                exactFit = true;
            else
            if(s.equalsIgnoreCase("-pngBitDepth"))
            {
                if(i + 1 < as.length)
                {
                    int j = -1;
                    try
                    {
                        int l = Integer.valueOf(as[++i]).intValue();
                        switch(l)
                        {
                        case 8: // '\b'
                            j = 0;
                            break;

                        case 24: // '\030'
                            j = 1;
                            break;

                        case 32: // ' '
                            j = 2;
                            break;
                        }
                    }
                    catch(NumberFormatException _ex)
                    {
                        j = -1;
                    }
                    if(j >= 0 && j <= 2)
                    {
                        defaultBitDepth = j;
                    } else
                    {
                        log(getResString("DashBitDepthInvalidArg"));
                        usage(false);
                        return false;
                    }
                } else
                {
                    log(getResString("DashBitDepthRequiresArg"));
                    usage(false);
                    return false;
                }
            } else
            {
                log(getResString("InvalidFlag") + as[i]);
                return false;
            }
        }

        if(inputPath == null)
        {
            log(getResString("InputFileError"));
            return false;
        }
        if(flashPath == null && gifPath == null && serverMapPath == null && clientMapPath == null && projectorWPath == null && projectorMPPCPath == null && jpegPath == null && QTMPath == null && pngPath == null && txtPath == null)
        {
            log(getResString("NothingToDo"));
            return false;
        } else
        {
            return true;
        }
    }

    protected void usage(boolean flag, String s)
    {
        if(flag)
        {
            if(serial != null)
            {
                if(!serial.getLimited())
                    log(getResString("Title") + " " + getResString("Version") + " " + getResString("Build") + " - " + getResString("BuildDate"));
                else
                    log(getResString("Title") + " " + getResString("Version") + " " + getResString("DevBuild") + " - " + getResString("BuildDate"));
            } else
            {
                log(getResString("Title") + " " + getResString("Version") + " " + getResString("DevBuild") + " - " + getResString("BuildDate"));
            }
            log(getResString("Copyright"));
        }
    }
}