Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GDropFiles.h

00001 #ifndef __DROP_FILES__
00002 #define __DROP_FILES__
00003 
00004 #if defined WIN32
00005 #include <Shlobj.h>
00006 #elif defined LINUX
00007 #include "GToken.h"
00008 #endif
00009 #include "GVariant.h"
00010 
00011 class GDropFiles : public List<char>
00012 {
00013 public:
00014     GDropFiles(GVariant &v)
00015     {
00016         #if defined WIN32
00017         DROPFILES *Df = v.IsBinary() AND v.Value.Binary.Length >= sizeof(DROPFILES) ? (DROPFILES*)v.Value.Binary.Data : 0;
00018         if (Df)
00019         {
00020             void *FilesPtr = ((char*)Df) + Df->pFiles;
00021             if (Df->fWide)
00022             {
00023                 char16 *f = (char16*)FilesPtr;
00024                 while (*f)
00025                 {
00026                     char *Utf8 = LgiNewUtf16To8(f);
00027                     if (Utf8) Insert(Utf8);
00028                     f += StrlenW(f) + 1;
00029                 }
00030             }
00031             else
00032             {
00033                 char *f = (char*)FilesPtr;
00034                 while (*f)
00035                 {
00036                     Insert((char*)LgiNewConvertCp("utf-8", f, LgiAnsiToLgiCp()));
00037                     f += strlen(f) + 1;
00038                 }
00039             }
00040         }
00041         #elif defined LINUX
00042         if (v.IsBinary())
00043         {
00044             GToken Uri( (char*)v.Value.Binary.Data,
00045                         "\r\n,",
00046                         true,
00047                         v.Value.Binary.Length);
00048 
00049             for (int i=0; i<Uri.Length(); i++)
00050             {
00051                 char *File = Uri[i];
00052 
00053                 // Remove leading 'File:'
00054                 if (strnicmp(File, "file:", 5) == 0) File += 5;
00055 
00056                 // Decode URI
00057                 char *i = File, *o = File;
00058                 while (*i)
00059                 {
00060                     if (*i == '%')
00061                     {
00062                         char h[3] = { i[1], i[2], 0 };
00063                         *o++ = htoi(h);
00064                         i += 3;
00065                     }
00066                     else
00067                     {
00068                         *o++ = *i++;
00069                     }
00070                 }
00071                 *o++ = 0;
00072 
00073                 // Check file exists..
00074                 if (FileExists(File))
00075                 {
00076                     Insert(NewStr(File));
00077                 }
00078             }
00079         }
00080         else printf("GDropFiles: Type not binary.\n");
00081         #endif
00082     }
00083 
00084     ~GDropFiles()
00085     {
00086         DeleteArrays();
00087     }
00088 };
00089 
00090 #endif

Generated on Wed Oct 26 14:46:48 2005 for Lgi by  doxygen 1.4.1