FXWinLinks.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                                 Windows Links                                 *
00004 *                                                                               *
00005 *********************************************************************************
00006 *        Copyright (C) 2005 by Niall Douglas.   All Rights Reserved.            *
00007 *       NOTE THAT I DO NOT PERMIT ANY OF MY CODE TO BE PROMOTED TO THE GPL      *
00008 *********************************************************************************
00009 * This code is free software; you can redistribute it and/or modify it under    *
00010 * the terms of the GNU Library General Public License v2.1 as published by the  *
00011 * Free Software Foundation EXCEPT that clause 3 does not apply ie; you may not  *
00012 * "upgrade" this code to the GPL without my prior written permission.           *
00013 * Please consult the file "License_Addendum2.txt" accompanying this file.       *
00014 *                                                                               *
00015 * This code is distributed in the hope that it will be useful,                  *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                          *
00018 *********************************************************************************
00019 * $Id:                                                                          *
00020 ********************************************************************************/
00021 
00022 #ifndef FXWINLINKS_H
00023 #define FXWINLINKS_H
00024 
00025 #include "FXString.h"
00026 
00027 namespace FX {
00028 
00033 class QFileInfo;
00034 
00094 struct FXAPI FXWinShellLink
00095 {
00096     struct FXAPI Header
00097     {
00098         FXuint length;
00099         char guid[16];
00100         union Flags
00101         {
00102             struct
00103             {
00104                 FXuint hasItemIdList : 1;
00105                 FXuint pointsToFileOrDir : 1;
00106                 FXuint hasDescription : 1;
00107                 FXuint hasRelativePath : 1;
00108                 FXuint hasWorkingDir : 1;
00109                 FXuint hasCmdLineArgs : 1;
00110                 FXuint hasCustomIcon : 1;
00111                 FXuint useWorkingDir : 1;       // Seems to need to be set to enable working dir
00112                 FXuint unused : 24;
00113             };
00114             FXuint raw;
00115         } flags;
00116         union FileAttribs
00117         {   // = return from GetFileAttributes()
00118             struct
00119             {
00120                 FXuint isReadOnly : 1;
00121                 FXuint isHidden : 1;
00122                 FXuint isSystem : 1;
00123                 FXuint isVolumeLabel : 1;
00124                 FXuint isDir : 1;
00125                 FXuint isModified : 1;  // =archive bit set, ie; is a file normally
00126                 FXuint isEncrypted : 1;
00127                 FXuint isNormal : 1;    // Doesn't seem to get set
00128                 FXuint isTemporary : 1;
00129                 FXuint isSparse : 1;
00130                 FXuint hasReparsePoint : 1;
00131                 FXuint isCompressed : 1;
00132                 FXuint isOffline : 1;
00133                 FXuint unused : 19;
00134             };
00135             FXuint raw;
00136         } fileattribs;      // in GetFileAttributes() format
00137         FXulong creation, modified, lastAccess; // in FILETIME format
00138         FXuint filelength;
00139         FXuint iconno;
00140         enum ShowWnd
00141         {
00142             HIDE=0,
00143             NORMAL,
00144             SHOWMINIMIZED,
00145             SHOWMAXIMIZED
00146         };
00147         ShowWnd showWnd;
00148         FXuint hotkey;
00149         FXuint unknown1, unknown2;
00150 
00151         Header()
00152         {
00153             memset(this, 0, sizeof(*this));
00154             static const char linkguid[]={
00155                 0x01, 0x14, 0x02, 0x00,
00156                 0x00, 0x00,
00157                 0x00, 0x00,
00158                 (char) 0xc0, 0x00,
00159                 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 };
00160             length=0x4c;
00161             memcpy(guid, linkguid, sizeof(guid));
00162             showWnd=NORMAL;
00163         }
00164 
00165         friend FXAPI FXStream &operator<<(FXStream &s, const Header &i);
00166         friend FXAPI FXStream &operator>>(FXStream &s, Header &i);
00167     } header;
00168     /* Had to reverse engineer this myself!
00169     First item is guid of what I assume means "My Computer"
00170       +0: length of item (always 0x14=20 bytes)
00171       +2: Always 18 bytes:
00172         0x1f, 0x50, 0xe0, 0x4f, 0xd0, 0x20, 0xea, 0x3a,
00173         0x69, 0x10, 0xa2, 0xd8, 0x08, 0x00, 0x2b, 0x30,
00174         0x30, 0x9d
00175     Next item is drive:
00176       +0: length of item (always 0x19=25 bytes)
00177       +2: byte 0x2f
00178       +3: Drive in ASCII for 22 bytes
00179     Next comes path items:
00180       +0: length of overall item
00181       +2: short 0x31 for dir, 0x32 for file
00182       +4: int size of file (=0 for dir)
00183       +8: int created       d:\windows=0x63893326, c:\windows=0x052D3321, c:\downloads=0x48853328
00184       +12: GetFileAttributes() for entry
00185       +14: Null terminated ASCII short filename version (padded to two byte multiple)
00186      On WinXP only:
00187       +n: length of this item
00188       +n+2: short 0x3
00189       +n+4: short 0x4
00190       +n+6: short 0xbeef
00191       +n+8: int modified    d:\windows=0x8de5328c, c:\windows=0x63c43297, c:\downloads=0x76e8331a
00192       +n+12: int lastRead   d:\windows=0x49843328, c:\windows=0x41fa3328, c:\downloads=0x48853328
00193       +n+16: int 0x14
00194       +n+20: Null terminated Unicode version
00195       +n+m: Two bytes (unknown)
00196     */
00197     struct FXAPI ItemIdListTag
00198     {
00199         FXushort length;
00200         char path1[260];            // In ASCII
00201         FXnchar path2[260];     // In unicode
00202         ItemIdListTag()
00203         {
00204             memset(this, 0, sizeof(*this));
00205         }
00206         friend FXAPI FXStream &operator<<(FXStream &s, const ItemIdListTag &i);
00207         friend FXAPI FXStream &operator>>(FXStream &s, ItemIdListTag &i);
00208         char originalPath[260];     // [not in lnk file] Used so code knows the non-decoded path
00209     } itemIdList;
00210     struct FXAPI FileLocationTag
00211     {
00212         FXuint length;          // to end of whole tag
00213         FXuint firstOffset;     // to end of this tag header
00214         union Flags
00215         {
00216             struct
00217             {
00218                 FXuint onLocalVolume : 1;
00219                 FXuint onNetworkShare : 1;
00220                 FXuint unused : 30;
00221             };
00222             FXuint raw;
00223         } flags;
00224         struct FXAPI LocalVolume
00225         {
00226             FXuint length;
00227             enum Type
00228             {
00229                 Unknown=0,
00230                 NoRoot,
00231                 Removable,  // ie; floppy, usb drive etc.
00232                 Fixed,      // ie; hard disc
00233                 Remote,     // ie; network share
00234                 CDROM,
00235                 RamDrive
00236             };
00237             Type type;
00238             FXuint serialNo;
00239             char volumeLabel[64];
00240             LocalVolume()
00241             {
00242                 memset(this, 0, sizeof(*this));
00243             }
00244             friend FXAPI FXStream &operator<<(FXStream &s, const LocalVolume &i);
00245             friend FXAPI FXStream &operator>>(FXStream &s, LocalVolume &i);
00246         } localVolume;
00247         char basePath[260];
00248         struct FXAPI NetworkVolume
00249         {
00250             FXuint length;
00251             FXuint type;
00252             FXchar shareName[260];
00253             NetworkVolume()
00254             {
00255                 memset(this, 0, sizeof(*this));
00256                 type=0x2;
00257             }
00258             friend FXAPI FXStream &operator<<(FXStream &s, const NetworkVolume &i);
00259             friend FXAPI FXStream &operator>>(FXStream &s, NetworkVolume &i);
00260         } networkVolume;
00261         char remainingPath[64];
00262 
00263         FileLocationTag()
00264         {
00265             memset(this, 0, sizeof(*this));
00266             firstOffset=0x1c;
00267         }
00268         friend FXAPI FXStream &operator<<(FXStream &s, const FileLocationTag &i);
00269         friend FXAPI FXStream &operator>>(FXStream &s, FileLocationTag &i);
00270     } fileLocation;
00271     struct FXAPI StringTag
00272     {
00273         FXushort length;            // in characters
00274         FXnchar string[260];        // Unicode string
00275         StringTag() { memset(this, 0, sizeof(*this)); }
00276         friend FXAPI FXStream &operator<<(FXStream &s, const StringTag &i);
00277         friend FXAPI FXStream &operator>>(FXStream &s, StringTag &i);
00278     };
00279     StringTag description;
00280     StringTag relativePath;
00281     StringTag workingDir;
00282     StringTag cmdLineArgs;
00283     StringTag customIcon;
00284     friend FXAPI FXStream &operator>>(FXStream &s, FXWinShellLink &i);
00285 
00288     void write(FXStream s, const QFileInfo &whereTo);
00289 
00292     static FXString read(const FXString &path, bool doDriveConversion=true);
00295     static void write(const FXString &path, const QFileInfo &whereTo);
00296 
00297 };
00298 
00299 
00325 struct FXAPI FXWinJunctionPoint
00326 {
00327 private:
00328     FXWinJunctionPoint();
00329     ~FXWinJunctionPoint();
00330 public:
00332     static bool test(const FXString &path);
00334     static FXString read(const FXString &path);
00336     static void write(const FXString &path, const QFileInfo &whereTo);
00338     static void remove(const FXString &path);
00339 };
00340 
00341 } // namespace
00342 
00343 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:25 2009 for TnFOX by doxygen v1.4.7