include/df/syscode.hpp

00001 /*
00002 SystemCode/Data - holds most common code/data for DigiForce
00003 Notes:
00004 - The sizeof(SystemCode) must be zero
00005 so it can be derived from into any class without wasting memory.
00006 Therefore no virtual members allowed (which would require a vtable)
00007 */
00008 
00009 class SystemDataClass {
00010   public:
00011     //System wide data (static data only!)
00012     BOOL IgnoreExceptions[256];
00013     char *ExceptionMsgs[256];
00014     Thread *MainThread;
00015     BOOL KeysStatus[256];
00016     BOOL b_trace; //enable tracing (see trace.hpp)
00017     Window *ActiveWindow;
00018     //SystemCode::LoadResources() will load all elements below
00019     //Dialog default font/mouse
00020     Font *fnt;
00021     Mouse *mouse;
00022     //Explorer class default icons (16x16)
00023     Bitmap *icon_file;
00024     Bitmap *icon_folder;
00025     Bitmap *icon_drive;
00026     Bitmap *icon_plus;  //DF/3.0
00027     Bitmap *icon_minus; //DF/3.0
00028     //GetFileName Dialog icons (32x32)
00029     Bitmap *icon_parentpath;
00030     Bitmap *icon_makepath;
00031 };
00032 
00033 extern SystemDataClass *SystemData;
00034 
00035 //Find & Replace callback flags
00036 #define FR_FLG_WHOLE 1
00037 #define FR_FLG_CASE  2
00038 //Find & Replace events
00039 #define FR_EVENT_FIND       1  //FindDialog(), ReplaceDialog()
00040 #define FR_EVENT_REPLACE    2  //ReplaceDialog() only
00041 #define FR_EVENT_REPLACEALL 3  //ReplaceDialog() only
00042 
00043 class FindReplaceDialogCallback {
00044   public:
00045     virtual BOOL Event(char *findstr, char *newstr, int event, int flgs);
00046 };
00047 
00048 class SystemCode {
00049   public:
00050     static void LoadResources();
00051     //Public definitions
00052     static void DefaultExceptionHandler(uint8 except);
00053     //Stack functions
00054     static void SetStackSize(uint32);  //sets stack size for new threads (def=64k)
00055     static uint32 GetStackSize();      //returns stack size of new threads
00056     //Exception handlers
00057     static void RaiseException(uint8 except);
00058     //control default action for exceptions
00059     static void IgnoreException(uint8 except, BOOL _ignore) {
00060       SystemData->IgnoreExceptions[except] = _ignore ? TRUE : FALSE;
00061     }
00062     static void SetExceptionMsg(uint8 except, char *msg);
00063     static char *GetExceptionMsg(uint8 except);
00064     static BOOL DefaultEventHandler(Element *id, int msg, int x, int y, int flgs);
00065     static BOOL DefaultEventHandler(Network *id, int msg, int x, int y, int flgs);
00066     static BOOL DefaultEventHandler(Thread *id, int msg, int x, int y, int flgs);
00067     //LastError
00068     static void StaticSetLastErrorMsg(char *, ...);
00069     static char *StaticGetLastErrorMsg();
00070     static void StaticSetLastError(int code);
00071     static uint32 StaticGetLastError();
00072     //get info
00073     static BOOL GetUserName(String &s);
00074     static BOOL GetComputerName(String &s);
00075     static BOOL GetExecutableFilename(String &s);
00076     //misc stuff
00077     static BOOL SetServiceStatus(BOOL state);
00078     static void ProcessQueue(BOOL wait4msg);
00079     //Translate/Dispatchs messages
00080     //bkgnd_wait = causes WaitMessage() to be called if app is not active
00081     static void WaitMessage();  //waits till a message is available for processing
00082     static BOOL IsQueueEmpty();
00083     static BOOL WakeThread(Thread *);  //posts a NULL message to thread
00084     static BOOL PostMessage(Thread *, uint32 msg, iPTR wParam, iPTR lParam);
00085     static BOOL PostMessage(Window *, uint32 msg, iPTR wParam, iPTR lParam);
00086     static BOOL CreateLink(char *PathObj, char *PathLink, char *WorkPath, char *Desc = (char*)NULL, char *Args = (char*)NULL);
00087     static BOOL CreateStartMenuItem(char *menupath, char *app, char *title, char *args = (char*)NULL);
00088     //expand environment strings in a string
00089     static void ExpandEnvironmentStrings(String &str);  //expands %var% in str
00090     static int CmpVersion(Version &v1, Version &v2);  //0=same -1=v1 newer 1=v2 newer
00091     //dialogs
00092     static void DialogInit(Font *, Mouse *);  //set your own custom Font/Mouse for dialog boxes below (not required)
00093     static int Message(char *msg, char *title = "Application Message", char *t1 = "OK", char *t2 = NULL, char *t3 = NULL);
00094     static BOOL GetFileName(char *title, String &path, String &filename, char *types = (char*)NULL, int typeidx = 0, BOOL open = TRUE, BOOL folder = FALSE);
00095     static BOOL GetString(char *title, char *desc, String &str, char *badchars = (char*)NULL, char *goodchars = (char*)NULL);
00096     static BOOL FindDialog(char *title, String &str, FindReplaceDialogCallback *cb, int &flgs);
00097     static BOOL ReplaceDialog(char *title, String &oldstr, String &newstr, FindReplaceDialogCallback *cb, int &flgs);
00098     //command line parameters
00099     static char *GetParameter(uint8 idx);
00100     static uint32 GetParameterCount();
00101     //thread stuff
00102     static Thread *GetCurrentThread();  //returns 'this' for current thread
00103     //even outside of class code (uses ThreadID lookup in List table)
00104     static void Exit(uint32 ExitCode = 0);  //Terminate Thread
00105     static void ExitErrorMsg();
00106     static void ExitErrorMsg(char *msg,...);
00107     //memory stuff
00108     static PTR MemAlloc(uint32 siz, uint32 flgs = 0);
00109     static PTR MemAllocZ(uint32 siz, uint32 flgs = 0);
00110     static PTR MemReAlloc(PTR ptr, uint32 siz);
00111     static PTR MemReAlloc(PTR *ptr, uint32 siz) { return (*ptr = MemReAlloc(*ptr, siz)); }
00112     static BOOL MemFree(PTR ptr);
00113     static uint32 MemAvailPhys();  //returns physical memory free
00114     static uint32 MemAvailVir();  //returns v-memory free (swapfile)
00115     //if MEM_FIXED (default) is not used with Alloc(flgs) you may need these
00116     static PTR Lock(PTR);
00117     static BOOL Unlock(PTR);
00118     static char **GetEnvironmentStrings();
00119     static BOOL GetEnvironmentVariable(char *vname, String &ret);
00120     static BOOL SetEnvironmentVariable(char *vname, char *vdata);
00121     static BOOL IsWindowsNT();
00122     //Console functions (use only if you compile with /CON !!!)
00123 #ifdef _CONSOLE
00124     static void Print(char *);      //no formatting
00125     static void DirectPrint(PTR, uint32 len);   //no CR/LF conversion done
00126     static void DirectPrint(char *);
00127 #endif
00128     //C-style string/mem functions
00129     static char *strcpy(char *dest, const char *src);   //dest/src may overlap
00130     static char *strcpy(String &dest, const char *src);  //dest/src may overlap
00131     static char *strcat(char *dest, const char *src);
00132     static char *strcat(String &dest, const char *src);
00133     static int strcmp(const char *s1, const char *s2);
00134     static int stricmp(const char *s1, const char *s2);
00135     static char *strdup(const char *s);    //make dup using Alloc()
00136     static char *strchr(char const *s, char c);
00137     static char *strrchr(char const *s, char c);  //DF/1.6.2
00138     static char *strset(char *s, char c);   //set entire string to c
00139     static int strlen(char const *s);
00140     static char *strupr(char *s);
00141     static char toupper(char);
00142     static char *strlwr(char *s);
00143     static char tolower(char);
00144     static void *memcpy(void *dest, void const *src, int len);  //dest/src may overlap
00145     static int memcmp(const void *s1, const void *s2, int len);
00146     static int memicmp(const void *s1, const void *s2, int len);
00147     static void *memchr(const void *s, char c, int len);  //return NULL on not found
00148     static void *memset(void *s, uint8 c, int len);
00149     static void *memset16(void *s, uint16 c, int len);
00150     static void *memset24(void *s, uint32 c, int len);
00151     static void *memset32(void *s, uint32 c, int len);
00152     static int vsnprintf(char *, int, const char *, va_list arg);
00153     static int vsprintf(String &, const char *, va_list arg);
00154     static int vsprintf(char *, const char *, va_list arg);
00155     static int sprintf(String &, const char *, ...);
00156     static int sprintf(char *, const char *, ...);
00157     static int vprintf(const char *, va_list);
00158     static int printf(const char *, ...);
00159     static int strncmp(const char *s1, const char *s2, int len); //DF/1.0.7
00160     static int strnicmp(const char *s1, const char *s2, int len); //DF/1.0.7
00161 
00162     //Introduced into SystemCode class in DF/1.2.3
00163     static uint32 atox(const char *);  //defined in DF/0.5.4
00164     static uint32 atox64(const char *);  //defined in DF/4.3.2
00165     static uint32 atou(const char *);  //defined in DF/1.0.5 (unsigned version of atoi)
00166     static int atol(const char *);
00167     static int atoi(const char *);
00168 
00169     //Date/time functions
00170     static void GetTime(Time *);
00171     static BOOL SetTime(Time *);  //ignores Time.DayOfWeek
00172     static void Sleep(uint32);    //sleep x milliseconds
00173     static uint32 GetSeconds();   //get seconds since Y2K
00174     //Thread related members
00175     static BOOL TerminateThread(Thread *x);
00176     static void TerminateProcess(uint32 ec);
00177     static BOOL GetExitCode(Thread *x, uint32 *ExitCode);
00178     static BOOL IsThreadActive(Thread *x);
00179     static uint32 GetThreadCount();  //master list
00180     static uint32 GetCurrentProcessId();
00181     static uint32 GetCurrentThreadId();
00182     static uint32 GetCurrentThreadHandle();  //returns Win32 Handle
00183     //use Thread *GetCurrentThread(); to return current Thread (ie: 'this')
00184 
00185     static BOOL StartThread(Thread *);
00186     static BOOL StopThread(Thread *);
00187     static BOOL ResumeThread(Thread *);
00188     static BOOL PauseThread(Thread *);
00189 
00190     static Thread *FindThread(uint32 handle);  //by handle DF/1.4.1
00191 
00192     static BOOL ExecuteFile(char *f, char *cmd = "open");  //checks Registry to Execute file
00193 
00194     static BOOL SystemLogOff(BOOL force = FALSE);
00195     static BOOL SystemPowerOff(BOOL force = FALSE);
00196     static BOOL SystemReboot(BOOL force = FALSE);
00197     static BOOL SystemShutdown(BOOL force = FALSE);
00198     //OS functions
00199     static void ConvertPathStyle(char *);  //converts path to current OS style (ie: linux: '\\' -> '/')
00200     //user functions
00201     static BOOL GetCurrentUser(String &s) { return GetUserName(s);}
00202     static BOOL LoginAsUser(char *user, char *pwd);
00203     //unix password functions
00204     static BOOL UnixCrypt(char *textToEncrypt, String &output);
00205     static BOOL UnixCrypt(char *encryptionSalt, char *textToEncrypt, String &output);  //encryptionSalt must be 2 printable chars
00206     //endian conversion functions
00207     static void SwapByteOrder(int16 &);
00208     static void SwapByteOrder(int32 &);
00209     static void SwapByteOrder(int64 &);
00210     static void SwapByteOrder(uint16 &);
00211     static void SwapByteOrder(uint32 &);
00212     static void SwapByteOrder(uint64 &);
00213 };
00214 

Generated on Mon Mar 5 09:49:14 2007 for DigiForce by  doxygen 1.4.7