fixed empty CVS checkin.
authorkramm <kramm>
Mon, 15 Nov 2004 11:08:24 +0000 (11:08 +0000)
committerkramm <kramm>
Mon, 15 Nov 2004 11:08:24 +0000 (11:08 +0000)
installer/Makefile
installer/archive.c
installer/archive.h
installer/crnfiles.c
installer/depack.c
installer/depack.h
installer/installer.c

index e69de29..de58c83 100644 (file)
@@ -0,0 +1,18 @@
+CC=/opt/xmingw/bin/i386-mingw32msvc-gcc -DWIN32
+
+all: installer.exe
+
+LIBS=-lgdi32 -lshlwapi 
+
+crnfiles.o: crnfiles.c
+       $(CC) -c crnfiles.c
+
+depack.o: depack.c depack.h Makefile
+       $(CC) -c depack.c -o depack.o
+
+archive.o: archive.c archive.c depack.h
+       $(CC) -c archive.c -o archive.o
+
+installer.exe: installer.c depack.o archive.o depack.h crnfiles.o Makefile
+       $(CC) installer.c depack.o archive.o crnfiles.o -o installer.exe $(LIBS)
+
index e69de29..82c2de5 100644 (file)
@@ -0,0 +1,222 @@
+/* archive.c
+
+   Part of the swftools installer.
+   
+   Copyright (c) 2004 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#ifdef WIN32
+#include <windows.h>
+#include <shlwapi.h>
+#else
+#include <sys/stat.h>
+#endif
+#include "archive.h"
+#include "depack.h"
+
+
+typedef struct _reader
+{
+    unsigned char*mem;
+    int readpos;
+} reader_t;
+
+static void myread(void*self, void*mem, int len)
+{
+    /*if(readpos+len >= sizeof(crndata)) {
+       len = sizeof(crndata) - readpos;
+    }*/
+    reader_t*r = (reader_t*)self;
+    memcpy(mem, r->mem+r->readpos, len);
+    r->readpos += len;
+    //return len;
+}
+
+typedef  struct _writer
+{
+    unsigned char*mem;
+    int memlen;
+} writer_t;
+
+static void mywrite(void*self, void*buf, int len)
+{
+    writer_t*w = (writer_t*)self;
+    memcpy(w->mem+w->memlen, buf, len);
+    w->memlen += len;
+}
+
+static int verbose = 0;
+static void msg(char*format, ...)
+{
+    char buf[1024];
+    int l;
+    va_list arglist;
+    if(!verbose)
+       return;
+    va_start(arglist, format);
+    vsprintf(buf, format, arglist);
+    va_end(arglist);
+    l = strlen(buf);
+    while(l && buf[l-1]=='\n') {
+       buf[l-1] = 0;
+       l--;
+    }
+    printf("(archive) %s\n", buf);
+    fflush(stdout);
+}
+
+static int create_directory(char*path,statusfunc_t f)
+{
+    if(!path || !*path || (*path=='.' && (!path[1] || path[1]=='.')))
+       return 1; //nothing to do
+    while(path[0]=='.' && (path[1]=='/' || path[1]=='\\'))
+       path+=2;
+
+#ifdef WIN32
+    if(PathIsDirectoryA(path))
+       return 1;
+#else
+    struct stat st;
+    if(stat(path, &st)>=0) {
+       if(S_ISDIR(st.st_mode)) {
+           return 1; /* already exists */
+       }
+    }
+#endif
+
+    if(mkdir(path,0755)<0) {
+       char buf[1024];
+       sprintf(buf, "create directory \"%s\" FAILED", path);
+       f(-1, buf);
+       return 0;
+    }
+    return 1;
+}
+static int goto_directory(char*path,statusfunc_t f)
+{
+    if(chdir(path)<0) {
+       char buf[1024];
+       sprintf(buf, "changing to directory \"%s\" FAILED", path);
+       f(-1, buf);
+       return 0;
+    }
+    return 1;
+}
+static char basenamebuf[256];
+static char*get_directory(char*filename)
+{
+    char*r1 = strrchr(filename, '\\');
+    char*r2 = strrchr(filename, '/');
+    char*r = r1>r2?r1:r2;
+    if(!r)
+       return "";
+    memcpy(basenamebuf, filename, r-filename);
+    basenamebuf[r-filename] = 0;
+    //msg("directory name of \"%s\" is \"%s\"", filename, basenamebuf);
+    return basenamebuf;
+}
+static int write_file(char*filename, void*mem, int len,statusfunc_t f)
+{
+    while(filename[0]=='.' && (filename[1]=='/' || filename[1]=='\\'))
+       filename+=2;
+
+    filename=strdup(filename);
+
+    char*p = filename;
+    while(*p) {
+       if(*p=='/') *p='\\';
+       p++;
+    }
+
+    msg("create file \"%s\" (%d bytes)", filename, len);
+    FILE*fo = fopen(filename, "wb");
+    if(!fo) {
+       char buf[1024];
+       sprintf(buf, "Couldn't create file %s", filename);
+       f(-1, buf);
+       free(filename);
+       return 0;
+    }
+    fwrite(mem, len, 1, fo);
+    fclose(fo);
+    free(filename);
+    return 1;
+}
+
+int unpack_archive(void*data, char*destdir, statusfunc_t f)
+{
+    depack_t d;
+
+    reader_t r;
+    r.mem = (unsigned char*)data;
+    r.readpos = 0;
+    
+    f(0, "Reading compressed data");
+    depack_init(&d,&r,myread);
+    
+    writer_t w;
+    w.mem = malloc(d.size);
+    w.memlen = 0;
+
+    f(0, "Decompressing data");
+    depack_process(&d,&w,mywrite);
+    depack_destroy(&d);
+
+    f(0, "Creating installation directory");
+    if(!create_directory(destdir,f)) return 0;
+    f(0, "Changing to installation directory");
+    if(!goto_directory(destdir,f)) return 0;
+
+    f(0, "Copying files...");
+    int pos = 0;
+    while(pos<w.memlen) {
+       unsigned char*mem = w.mem;
+       /* read id */
+       unsigned char id[4];
+       id[3] = 0;
+       memcpy(id, &mem[pos], 3);
+       pos += 3;
+
+       /* read size */
+       int len = mem[pos]|mem[pos+1]<<8|mem[pos+2]<<16|mem[pos+3]<<24;
+       pos += 4;
+       
+       /* read filename */
+       char*filename = &mem[pos];
+       int l = strlen(filename);
+       pos+=l+1;
+
+       if(verbose) printf("[%s] %s %d\n", id, filename, len);
+       char buf[2048];
+       sprintf(buf, "[%s] %s (%d bytes)", id, filename, len);
+       f(0, buf);
+       if(*(U32*)id == *(U32*)"DIR") {
+           if(!create_directory(filename,f)) return 0;
+       } else {
+           if(!create_directory(get_directory(filename),f)) return 0;
+           if(!write_file(filename,mem+pos,len,f)) return 0;
+       }
+       
+       pos += len;
+    }
+    f(0, "Installation finished");
+    return 1;
+}
+
+
index e69de29..9334784 100644 (file)
@@ -0,0 +1,29 @@
+/* archive.h
+
+   Part of the swftools installer.
+   
+   Copyright (c) 2004 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef __archive_h__
+#define __archive_h__
+
+typedef void (*statusfunc_t)(int type, char*text);
+
+int unpack_archive(void*data, char*destdir, statusfunc_t f);
+
+#endif //__archive_h__
+
index e69de29..35a81a2 100644 (file)
@@ -0,0 +1,5 @@
+char* crndata =
+"\x0\xff\x7f\x0\x1c\x0\x0\x0\x8d\x0\x0)*\x2\x0\x34\x0\x0\x10\x0\x20\x0\x86\x0\xba"
+"\x1d\x1\x0NUL\xc\x0tesu\xc8\xba{fil\x0ho\x20w@\x0\x0wrd\xa"
+;
+
index e69de29..3f3343d 100644 (file)
@@ -0,0 +1,321 @@
+/* depack.c\r
+\r
+   Part of the swftools installer.\r
+   \r
+   Copyright (c) 1997-2004 Matthias Kramm <kramm@quiss.org> \r
\r
+   This program is free software; you can redistribute it and/or modify\r
+   it under the terms of the GNU General Public License as published by\r
+   the Free Software Foundation; either version 2 of the License, or\r
+   (at your option) any later version.\r
+\r
+   This program is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with this program; if not, write to the Free Software\r
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */\r
+\r
+#include "stdlib.h"\r
+#include "stdio.h"\r
+#include "depack.h"\r
+\r
+U32 dbittab[] = {\r
+    0x1,       0x2,       0x4,       0x8,\r
+    0x10,      0x20,      0x40,      0x80,\r
+    0x100,     0x200,     0x400,     0x800,\r
+    0x1000,    0x2000,    0x4000,    0x8000,\r
+    0x10000,   0x20000,   0x40000,   0x80000, \r
+    0x100000,  0x200000,  0x400000,  0x800000,\r
+    0x1000000, 0x2000000, 0x4000000, 0x8000000,\r
+    0x10000000,0x20000000,0x40000000,0x80000000\r
+};\r
+\r
+static void* malloc_z(int len)\r
+{\r
+    void* buf = malloc(len);\r
+    if(buf == 0) {\r
+       fprintf(stderr, "\nout of memory\n");\r
+       exit(1);\r
+    }\r
+    memset(buf, 0, len);\r
+    return buf;\r
+}\r
+\r
+typedef struct _dpackead {\r
+    int back;\r
+    int len;\r
+} dpackead_t;\r
+\r
+typedef struct _tree {   \r
+    int depth;\r
+    U8  bits[17];\r
+    U32 base[17];\r
+} tree_t;\r
+\r
+typedef struct _depack_internal\r
+{\r
+    int DMEMSIZE;\r
+    int DMEMSIZEA;\r
+\r
+    tree_t T_REP;\r
+    tree_t T_STORE;\r
+    tree_t T_CNUM;\r
+    tree_t T_BACK;\r
+    tree_t T_BACK2;\r
+    tree_t T_BACK3;\r
+\r
+    dpackead_t dpackead;\r
+\r
+    void*reader;\r
+    readfunc_t readfunc;\r
+    void*writer;\r
+    writefunc_t writefunc;\r
+\r
+    U8* mem;\r
+    int mempos;\r
+    int pos;\r
+    U8 c;\r
+    U32 b;\r
+} depack_internal_t;\r
+\r
+void depack_destroy(depack_t*d)\r
+{\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+    free(i->mem);i->mem=0;\r
+    free(d->internal);d->internal=0;i=0;\r
+}\r
+\r
+static readbytes(depack_t*d, int num)\r
+{\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+\r
+    if(i->mempos+num<=i->DMEMSIZE) {\r
+       i->readfunc(i->reader, &i->mem[i->mempos],num);\r
+       i->writefunc(i->writer, &i->mem[i->mempos],num);\r
+    } else {\r
+       i->readfunc(i->reader, &i->mem[i->mempos],i->DMEMSIZE - i->mempos);\r
+       i->writefunc(i->writer, &i->mem[i->mempos],i->DMEMSIZE - i->mempos);\r
+       i->readfunc(i->reader, &i->mem[0],num-(i->DMEMSIZE - i->mempos));\r
+       i->writefunc(i->writer, &i->mem[0],num-(i->DMEMSIZE - i->mempos));\r
+    }\r
+    i->mempos=(i->mempos+num)&i->DMEMSIZEA;\r
+    i->pos+=num;\r
+}\r
+\r
+int move(U8*dest, U8*src, int len)\r
+{\r
+    if(len) do {\r
+       *dest=*src;\r
+       src++;\r
+       dest++;\r
+    } while(--len);\r
+}\r
+\r
+static lookback(depack_t*d, int back,int len)\r
+{\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+\r
+    int x,z=(i->mempos-back)&i->DMEMSIZEA;\r
+    char fail=0;\r
+\r
+    if(i->mempos+len <= i->DMEMSIZE && \r
+       z+len <= i->DMEMSIZE) \r
+    {\r
+       move(&i->mem[i->mempos],&i->mem[z],len);\r
+       i->writefunc(i->writer, &i->mem[i->mempos],len);\r
+       i->mempos=(i->mempos+len)&i->DMEMSIZEA;\r
+    } else {\r
+       for(x=0;x<len;x++) {\r
+           i->mem[i->mempos]=i->mem[z];\r
+           i->writefunc(i->writer, &i->mem[i->mempos],1);\r
+           i->mempos=(i->mempos+1)&i->DMEMSIZEA;\r
+           z=(z+1)&i->DMEMSIZEA;\r
+       }\r
+    }\r
+    i->pos += len;\r
+}\r
+\r
+static inline U8 readbit(depack_internal_t*i)\r
+{\r
+    i->c&=31;\r
+    if(i->c==0) i->readfunc(i->reader, &i->b,4);\r
+    return (i->b>>(31-i->c++))&1;\r
+}\r
+\r
+static inline U32 readval(depack_internal_t*i,int b)\r
+{\r
+    unsigned v=0;\r
+    signed char l;\r
+    for(l=b-1;l>=0;l--)\r
+       v|=readbit(i)<<l;\r
+    return v;\r
+}\r
+\r
+static tree_t gettree(depack_t*d)\r
+{\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+\r
+    int l;\r
+    int x,y,z=0,b=0,r;\r
+    tree_t tree;\r
+    memset(&tree, 0, sizeof(tree));\r
+   \r
+    tree.depth = readval(i,4)+1;\r
+\r
+    for(x=0;x<tree.depth;x++)\r
+    {\r
+       tree.base[x]=z;\r
+       r=0;while(!readbit(i)) r++;\r
+       if(readbit(i)) r=-r;\r
+       b+=r;\r
+       tree.bits[x]=b;\r
+       z+=dbittab[b];\r
+    }\r
+    tree.base[tree.depth]=z;\r
+    tree.bits[tree.depth]=0;\r
+    return tree;\r
+\r
+/*    for(z=0;z<=l;z++)\r
+    {\r
+       if(i->ttree[n].bits[z]>16) \r
+           printf(".");\r
+       else                       \r
+           printf("%c","0123456789abcdefg"[ttree[n].bits[z]]);\r
+    }\r
+    printf("\n");*/\r
+}\r
+\r
+static void showtree(tree_t tree)\r
+{\r
+    int t;\r
+    int last=0;\r
+    int lastbits = 0;\r
+    for(t=0;t<=tree.depth;t++)\r
+    {\r
+       if(t>0)\r
+           printf("[%d] %d: %05x-%05x (%d=%d+%d+1)\n",t,lastbits, last,tree.base[t],lastbits+(t-1)+1, lastbits,t-1);\r
+       last=tree.base[t];\r
+       lastbits = tree.bits[t];\r
+    }\r
+}\r
+\r
+static int gettreeval(depack_t*d, tree_t*tree)\r
+{\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+\r
+    U8 x=0;\r
+    while(!readbit(i)) x++;\r
+    if(x<17) return tree->base[x]+readval(i, tree->bits[x]);\r
+    else     return -1;\r
+}\r
+\r
+static int get_memsize(int b)\r
+{\r
+    int t,c=1;\r
+    for(t=0;;t++) {\r
+       if(c>=b) return c;\r
+       c<<=1;\r
+    }\r
+    return 0;\r
+}\r
+\r
+void depack_init(depack_t*d, void*reader, readfunc_t readfunc)\r
+{\r
+    d->internal = malloc_z(sizeof(depack_internal_t));\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+    if(i==0) {\r
+       fprintf(stderr, "depacker not initialized yet"); exit(1);\r
+    }\r
+\r
+    i->reader = reader;\r
+    i->readfunc = readfunc;\r
+\r
+    i->mempos=0;\r
+    i->pos=0;\r
+    i->b=i->c=0;\r
+\r
+    i->readfunc(i->reader,&i->dpackead.back, 4);\r
+    i->readfunc(i->reader,&i->dpackead.len, 4);\r
+\r
+    i->DMEMSIZE = get_memsize(i->dpackead.len);\r
+    i->DMEMSIZEA = i->DMEMSIZE-1;\r
+    i->mem = malloc_z(i->DMEMSIZE);\r
+\r
+    i->T_REP = gettree(d);\r
+    i->T_STORE = gettree(d);\r
+    i->T_CNUM = gettree(d);\r
+    //showtree(i->T_CNUM);\r
+    i->T_BACK = gettree(d);\r
+    //showtree(i->T_BACK);\r
+    i->T_BACK2 = gettree(d);\r
+    //showtree(i->T_BACK);\r
+    i->T_BACK3 = gettree(d);\r
+    //showtree(i->T_BACK3);\r
+\r
+    d->size = i->dpackead.len;\r
+}\r
+\r
+void depack_process(depack_t*d, void*writer,writefunc_t writefunc)\r
+{\r
+    depack_internal_t*i = (depack_internal_t*)d->internal;\r
+    i->writer = writer;\r
+    i->writefunc = writefunc;\r
+    while(i->pos<i->dpackead.len)\r
+    {\r
+       int store,rep,x;\r
+\r
+       store=gettreeval(d,&i->T_STORE)+1;\r
+\r
+       readbytes(d,store);\r
+\r
+       if(i->pos<i->dpackead.len)\r
+       {\r
+           rep = gettreeval(d,&i->T_REP)+1;\r
+\r
+           for(x=0;x<rep;x++)\r
+           {\r
+               int back,len;\r
+               len = gettreeval(d,&i->T_CNUM)+1;\r
+\r
+               if(len == 1) back = readval(i,3)+1;\r
+               if(len == 2) back = gettreeval(d,&i->T_BACK2)+1;\r
+               if(len == 3) back = gettreeval(d,&i->T_BACK3)+1;\r
+               if(len >= 4) back = gettreeval(d,&i->T_BACK)+1;\r
+\r
+               lookback(d,back,len);\r
+           }\r
+       }\r
+    }\r
+\r
+    if(i->pos!=i->dpackead.len) {\r
+       fprintf(stderr, "Internal error");\r
+       exit(1);\r
+    }\r
+}\r
+\r
+/*\r
+\r
+                mov eax,[b1]\r
+                mov ebx,[b2]\r
+                shld eax,ebx,cl\r
+                mov [b1],eax\r
+                shr ebx,cl\r
+                mov [b2],ebx\r
+                sub cnt,cl\r
+                cmp cnt,32-8\r
+                ja jj\r
+mm:             xor eax,eax\r
+                call read\r
+                shl eax,[cnt]\r
+                or  [b2],eax\r
+                add cnt,8\r
+                cmp cnt,32-8\r
+                jb mm\r
+jj:\r
+\r
+*/\r
+\r
+
index e69de29..028ab0c 100644 (file)
@@ -0,0 +1,41 @@
+/* depack.h\r
+\r
+   Part of the swftools installer.\r
+   \r
+   Copyright (c) 2004 Matthias Kramm <kramm@quiss.org> \r
\r
+   This program is free software; you can redistribute it and/or modify\r
+   it under the terms of the GNU General Public License as published by\r
+   the Free Software Foundation; either version 2 of the License, or\r
+   (at your option) any later version.\r
+\r
+   This program is distributed in the hope that it will be useful,\r
+   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+   GNU General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with this program; if not, write to the Free Software\r
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */\r
+\r
+#ifndef Depack_h\r
+#define Depack_h\r
+\r
+typedef unsigned long int U32;\r
+typedef unsigned char U8;\r
+\r
+typedef struct {\r
+    void*internal;\r
+    int pos;\r
+    int size;\r
+} depack_t;\r
+\r
+typedef void (*writefunc_t)(void*writer, void*mem, int len);\r
+typedef void (*readfunc_t)(void*reader, void*mem, int len);\r
+\r
+void depack_init(depack_t*d, void*reader, readfunc_t);\r
+void depack_process(depack_t*d, void*writer, writefunc_t);\r
+void depack_destroy(depack_t*d);\r
+\r
+#endif //Depack_h\r
+
index e69de29..397cd59 100644 (file)
@@ -0,0 +1,132 @@
+/* installer.c
+
+   Part of the swftools installer (Main program).
+   
+   Copyright (c) 2004 Matthias Kramm <kramm@quiss.org> 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "depack.h"
+
+#include "../config.h" //for swftools version
+
+extern char*crndata;
+
+LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    printf("%08x, %d %08x %08x\n", hwnd, message, wParam, lParam);
+    switch(message)
+    {
+       case WM_DESTROY:
+           PostQuitMessage(0);
+           break;
+       default:
+           return DefWindowProc(hwnd, message, wParam, lParam);
+    }
+    return 0;
+}
+
+#if USE_CONSOLE
+static HANDLE console;
+#endif
+static char*lastmessage = 0;
+void myarchivestatus(int type, char*text)
+{
+    DWORD written = 0;
+#if USE_CONSOLE
+    if(console) {
+       WriteConsole(console, text, strlen(text), &written, 0);
+       WriteConsole(console, "\n", 1, &written, 0);
+       fflush(stdout);
+    } 
+#endif
+    if(!written) {
+       printf("%s\n", text);
+    }
+
+    if(type<0) {
+       while(1) {
+           int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
+           
+           /* there is no MB_CANCEL, so, *sigh*, we have to display
+              the "retry" button. So pretend it's doing anything... */
+           if(ret==IDRETRY)
+               continue;
+           else
+               break;
+       }
+    }
+}
+
+int WINAPI WinMain(HINSTANCE me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
+{
+    WNDCLASS wcl;
+    char*install_dir = "C:\\swftools\\";
+
+    wcl.hInstance    = me;
+    wcl.lpszClassName= "SWFTools-Installer";
+    wcl.lpfnWndProc  = WindowFunc;
+    wcl.style        = 0; //default style
+    wcl.hIcon        = LoadIcon  (NULL, IDI_APPLICATION);
+    wcl.hCursor      = LoadCursor(NULL, IDC_ARROW);
+    wcl.lpszMenuName = NULL; //no menu
+    wcl.cbClsExtra   = 0;
+    wcl.cbWndExtra   = 0;
+    wcl.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
+
+    if(!RegisterClass(&wcl)) 
+       return 0;
+   
+#if USE_CONSOLE
+    FreeConsole();
+#endif
+   
+    char buf[1024];
+    sprintf(buf, "Do you want me to install SWFTools into the directory %s now?", install_dir);
+    int ret = MessageBox(0, buf, "SWFTools Install", MB_YESNO|MB_ICONQUESTION);
+
+    if(ret == IDNO)
+       return 0;
+    
+#if USE_CONSOLE
+    if(AllocConsole()) {
+       DWORD written;
+       console = GetStdHandle(STD_OUTPUT_HANDLE);
+       WriteConsole(console, "\r\n", 1, &written, 0);
+    }
+#endif
+
+    int success = unpack_archive(crndata, "C:\\swftools\\", myarchivestatus);
+
+#if USE_CONSOLE
+    FreeConsole();
+#endif
+
+    if(success) {
+       sprintf(buf, "SWFTools Version %s has been installed into %s successfully", VERSION, install_dir);
+       ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONINFORMATION);
+    } else {
+       /*sprintf(buf, "Installation failed\nLast message: %s", lastmessage);
+       ret = MessageBox(0, buf, "SWFTools Install", MB_OK|MB_ICONERROR);*/
+    }
+    exit(0);
+}
+
+
+