test/wxtest_physfs.cpp
author Ryan C. Gordon <icculus@icculus.org>
Mon, 23 Mar 2009 00:45:15 -0400
changeset 956 3da716cfe09f
parent 878 6d65c5e0049a
child 1082 94771621792f
permissions -rw-r--r--
Upped version to 2.0.0!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
878
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * Test program for PhysicsFS, using wxWidgets. May only work on Unix.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#if ( (defined(__MACH__)) && (defined(__APPLE__)) )
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#define PLATFORM_MACOSX 1
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <Carbon/Carbon.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#endif
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <stdio.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <stdlib.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <string.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <time.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#include <errno.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#include <wx/wx.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include <wx/treectrl.h>
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#include "physfs.h"
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
956
3da716cfe09f Upped version to 2.0.0!
Ryan C. Gordon <icculus@icculus.org>
parents: 878
diff changeset
    25
#define TEST_VER_MAJOR  2
3da716cfe09f Upped version to 2.0.0!
Ryan C. Gordon <icculus@icculus.org>
parents: 878
diff changeset
    26
#define TEST_VER_MINOR  0
3da716cfe09f Upped version to 2.0.0!
Ryan C. Gordon <icculus@icculus.org>
parents: 878
diff changeset
    27
#define TEST_VER_PATCH  0
878
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
//static PHYSFS_uint32 do_buffer_size = 0;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
enum WxTestPhysfsMenuCommands
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    // start with standard menu items, since using the wxIDs will map them
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    //  to sane things in the platform's UI (gnome icons in GTK+, moves the
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    //  about and quit items to the Apple menu on Mac OS X, etc).
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    MENUCMD_About = wxID_ABOUT,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    MENUCMD_Quit = wxID_EXIT,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
    // non-standard menu items go here.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    MENUCMD_Init = wxID_HIGHEST,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    MENUCMD_Deinit,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    MENUCMD_AddArchive,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    MENUCMD_Mount,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    MENUCMD_Remove,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    MENUCMD_GetCDs,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    MENUCMD_SetWriteDir,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    MENUCMD_PermitSymLinks,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    MENUCMD_SetSaneConfig,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    MENUCMD_MkDir,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    MENUCMD_Delete,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    MENUCMD_Cat,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    MENUCMD_SetBuffer,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
    MENUCMD_StressBuffer,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    MENUCMD_Append,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    MENUCMD_Write,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    MENUCMD_GetLastError,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
/*
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    { "getdirsep",      cmd_getdirsep,      0, NULL                         },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    { "getsearchpath",  cmd_getsearchpath,  0, NULL                         },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    { "getbasedir",     cmd_getbasedir,     0, NULL                         },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    { "getuserdir",     cmd_getuserdir,     0, NULL                         },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    { "getwritedir",    cmd_getwritedir,    0, NULL                         },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    { "getrealdir",     cmd_getrealdir,     1, "<fileToFind>"               },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    { "exists",         cmd_exists,         1, "<fileToCheck>"              },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    { "isdir",          cmd_isdir,          1, "<fileToCheck>"              },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    { "filelength",     cmd_filelength,     1, "<fileToCheck>"              },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    { "getlastmodtime", cmd_getlastmodtime, 1, "<fileToExamine>"            },
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
*/
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
};
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
class WxTestPhysfsFrame : public wxFrame
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
public:
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    WxTestPhysfsFrame(const wxChar *argv0);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    void rebuildTree();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    void onMenuInit(wxCommandEvent &evt);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    void onMenuDeinit(wxCommandEvent &evt);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    void onMenuAddArchive(wxCommandEvent &evt);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    void onMenuGetCDs(wxCommandEvent &evt);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
    void onMenuPermitSymLinks(wxCommandEvent &evt);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
private:
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    wxTreeCtrl *fileTree;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    wxTreeItemId stateItem;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    wxTreeItemId fsItem;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    int err(int success);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    void fillFileSystemTree(const char *path, const wxTreeItemId &item);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    void doInit(const char *argv0);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    void doDeinit();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    DECLARE_EVENT_TABLE()
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
};
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
BEGIN_EVENT_TABLE(WxTestPhysfsFrame, wxFrame)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
    EVT_MENU(MENUCMD_Init, WxTestPhysfsFrame::onMenuInit)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
    EVT_MENU(MENUCMD_Deinit, WxTestPhysfsFrame::onMenuDeinit)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    EVT_MENU(MENUCMD_AddArchive, WxTestPhysfsFrame::onMenuAddArchive)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    EVT_MENU(MENUCMD_GetCDs, WxTestPhysfsFrame::onMenuGetCDs)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    EVT_MENU(MENUCMD_PermitSymLinks, WxTestPhysfsFrame::onMenuPermitSymLinks)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
END_EVENT_TABLE()
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
// This is the the Application itself.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
class WxTestPhysfsApp : public wxApp
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
public:
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    WxTestPhysfsApp() : mainWindow(NULL) { /* no-op. */ }
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
    virtual bool OnInit();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
private:
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    WxTestPhysfsFrame *mainWindow;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
};
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
DECLARE_APP(WxTestPhysfsApp)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
static inline char *newstr(const char *str)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    char *retval = NULL;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    if (str != NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
        retval = new char[strlen(str) + 1];
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        strcpy(retval, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    return retval;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
} // newstr
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
static char *newutf8(const wxString &wxstr)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    #if wxUSE_UNICODE
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    size_t len = wxstr.Len() + 1;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    char *utf8text = new char[len * 6];
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    wxConvUTF8.WC2MB(utf8text, wxstr, len);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    return utf8text;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    #else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    return newstr(wxstr);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    #endif
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
} // newutf8
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
WxTestPhysfsFrame::WxTestPhysfsFrame(const wxChar *argv0)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    : wxFrame(NULL, -1, wxT("WxTestPhysfs"))
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    this->CreateStatusBar();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    wxMenuBar *menuBar = new wxMenuBar;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    wxMenu *stuffMenu = new wxMenu;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    stuffMenu->Append(MENUCMD_Init, wxT("&Init"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    stuffMenu->Append(MENUCMD_Deinit, wxT("&Deinit"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    stuffMenu->Append(MENUCMD_AddArchive, wxT("&Add Archive"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    stuffMenu->Append(MENUCMD_Mount, wxT("&Mount Archive"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    stuffMenu->Append(MENUCMD_Remove, wxT("&Remove Archive"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    stuffMenu->Append(MENUCMD_GetCDs, wxT("&Get CD-ROM drives"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    stuffMenu->Append(MENUCMD_SetWriteDir, wxT("&Set Write Dir"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    stuffMenu->Append(MENUCMD_SetSaneConfig, wxT("Set Sane &Config"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    stuffMenu->Append(MENUCMD_MkDir, wxT("M&kDir"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    stuffMenu->Append(MENUCMD_Delete, wxT("D&elete"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    stuffMenu->Append(MENUCMD_Cat, wxT("&Cat"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    stuffMenu->Append(MENUCMD_SetBuffer, wxT("Set &Buffer"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    stuffMenu->Append(MENUCMD_StressBuffer, wxT("Stress &Test Buffer"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    stuffMenu->Append(MENUCMD_Append, wxT("&Append"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    stuffMenu->Append(MENUCMD_Write, wxT("&Write"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    stuffMenu->Append(MENUCMD_Write, wxT("&Update getLastError"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    stuffMenu->AppendCheckItem(MENUCMD_PermitSymLinks, wxT("&Permit symlinks"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    menuBar->Append(stuffMenu, wxT("&Stuff"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    //wxMenu *helpMenu = new wxMenu;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    //helpMenu->Append(MENUCMD_About, wxT("&About\tF1"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    //menuBar->Append(helpMenu, wxT("&Help"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    this->SetMenuBar(menuBar);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    this->fileTree = new wxTreeCtrl(this, -1);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
    // The sizer just makes sure that fileTree owns whole client area.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
    sizer->Add(this->fileTree, 1, wxALL | wxEXPAND | wxALIGN_CENTRE);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    sizer->SetItemMinSize(this->fileTree, 1, 1);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    this->SetSizer(sizer);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    char *utf8argv0 = newutf8(wxString(argv0));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    this->doInit(utf8argv0);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
    delete[] utf8argv0;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
} // WxTestPhysfsFrame::WxTestPhysfsFrame
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
int WxTestPhysfsFrame::err(int success)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    if (success)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
        this->SetStatusText(wxT(""));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
        this->SetStatusText(wxString(PHYSFS_getLastError(), wxConvUTF8));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    return success;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
} // WxTestPhysfsFrame::err
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
void WxTestPhysfsFrame::fillFileSystemTree(const char *path,
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
                                           const wxTreeItemId &item)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
    char **rc = PHYSFS_enumerateFiles(path);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
    char **i;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    wxTreeItemId id;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    if (rc == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
        const wxString quote(wxT("'"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
        wxString str(wxT("Enumeration error: "));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
        str << quote << wxString(PHYSFS_getLastError(), wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
        id = this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
        this->fileTree->SetItemTextColour(id, wxColour(255, 0, 0));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
    else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
        for (i = rc; *i != NULL; i++)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
        {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
            id = this->fileTree->AppendItem(item, wxString(*i, wxConvUTF8));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
            const int len = strlen(path) + strlen(*i) + 2;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
            char *fname = new char[len];
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
            const char *origdir = path;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
            if (strcmp(origdir, "/") == 0)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
                origdir = "";
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
            snprintf(fname, len, "%s/%s", origdir, *i);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
            if (PHYSFS_isDirectory(fname))
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
            {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
                this->fileTree->SetItemTextColour(id, wxColour(0, 0, 255));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
                this->fillFileSystemTree(fname, id);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
            } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
            else if (PHYSFS_isSymbolicLink(fname))
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
            {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
                this->fileTree->SetItemTextColour(id, wxColour(0, 255, 0));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
            } // else if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
            else  // ...file.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
            {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
            } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
            delete[] fname;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
        } // for
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
        PHYSFS_freeList(rc);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
    } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
} // fillFileSystemTree
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
void WxTestPhysfsFrame::rebuildTree()
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
    const wxString dot(wxT("."));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
    const wxString quote(wxT("'"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
    wxTreeItemId item;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
    wxString str;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    const char *cstr = NULL;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    const bool wasInit = PHYSFS_isInit() ? true : false;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    this->fileTree->DeleteAllItems();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    wxTreeItemId root = this->fileTree->AddRoot(wxT("PhysicsFS"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    this->stateItem = this->fileTree->AppendItem(root, wxT("Library state"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
    str = wxT("Initialized: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    str << ((wasInit) ? wxT("true") : wxT("false"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    this->fileTree->AppendItem(this->stateItem, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    this->fileTree->Expand(this->stateItem);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    this->fileTree->Expand(root);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    // Fill in version information...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    PHYSFS_Version ver;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
    item = this->stateItem;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    str = wxT("wxtest_physfs version: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    str << TEST_VER_MAJOR << dot << TEST_VER_MINOR << dot << TEST_VER_PATCH;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
    this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
    PHYSFS_VERSION(&ver);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
    str = wxT("Compiled against PhysicsFS version: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
    str << (int) ver.major << dot << (int) ver.minor << dot << ver.patch;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
    this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    PHYSFS_getLinkedVersion(&ver);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    str = wxT("Linked against PhysicsFS version: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
    str << (int) ver.major << dot << (int) ver.minor << dot << ver.patch;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
    if (!wasInit)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
        return;   // nothing else to do before initialization...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
    str = wxT("Symbolic links permitted: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
    str << ((PHYSFS_symbolicLinksPermitted()) ? wxT("true") : wxT("false"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
    this->fileTree->AppendItem(this->stateItem, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
    str = wxT("Native directory separator: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    str << quote << wxString(PHYSFS_getDirSeparator(), wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
    this->fileTree->AppendItem(this->stateItem, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
    // Fill in supported archives...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    item = this->fileTree->AppendItem(this->stateItem, wxT("Archivers"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    const PHYSFS_ArchiveInfo **arcs = PHYSFS_supportedArchiveTypes();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    if (*arcs == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
        this->fileTree->AppendItem(item, wxT("(none)"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
    else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
        const PHYSFS_ArchiveInfo **i;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
        for (i = arcs; *i != NULL; i++)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
        {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
            const wxString ext((*i)->extension, wxConvUTF8);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
            const wxString desc((*i)->description, wxConvUTF8);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
            const wxString auth((*i)->author, wxConvUTF8);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
            const wxString url((*i)->url, wxConvUTF8);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
            wxTreeItemId arcitem = this->fileTree->AppendItem(item, ext);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
            this->fileTree->AppendItem(arcitem, desc);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
            this->fileTree->AppendItem(arcitem, auth);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
            this->fileTree->AppendItem(arcitem, url);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
        } // for
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
    } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
    // Fill in the standard paths...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
    item = this->fileTree->AppendItem(this->stateItem, wxT("Paths"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
    str = wxT("Base directory: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    str << quote << wxString(PHYSFS_getBaseDir(), wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    str = wxT("User directory: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    str << quote << wxString(PHYSFS_getUserDir(), wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    str = wxT("Write directory: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    if ((cstr = PHYSFS_getWriteDir()) == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
        str << wxT("(NULL)");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
    else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
        str << quote << wxString(cstr ? cstr : "(NULL)", wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
    this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
    //str = wxT("Preference directory: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    //str << wxString(PHYSFS_getUserDir(), wxConvUTF8);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
    //this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
    // Fill in the CD-ROMs...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
    item = this->fileTree->AppendItem(this->stateItem, wxT("CD-ROMs"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    char **cds = PHYSFS_getCdRomDirs();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    if (cds == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
        str = wxT("Error: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
        str << quote << wxString(PHYSFS_getLastError(), wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
        wxTreeItemId id = this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
        this->fileTree->SetItemTextColour(id, wxColour(255, 0, 0));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
    } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
    else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
        if (*cds == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
            this->fileTree->AppendItem(item, wxT("(none)"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
        else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
        {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
            char **i;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
            for (i = cds; *i != NULL; i++)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
                this->fileTree->AppendItem(item, wxString(*i, wxConvUTF8));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
        } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
        PHYSFS_freeList(cds);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
    } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    // Fill in search path...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
    item = this->fileTree->AppendItem(this->stateItem, wxT("Search path"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
    char **sp = PHYSFS_getSearchPath();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
    if (sp == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
        str = wxT("Error: ");
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
        str << quote << wxString(PHYSFS_getLastError(), wxConvUTF8) << quote;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
        wxTreeItemId id = this->fileTree->AppendItem(item, str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
        this->fileTree->SetItemTextColour(id, wxColour(255, 0, 0));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
    } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
        if (*sp == NULL)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
            this->fileTree->AppendItem(item, wxT("(none)"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
        else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
        {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
            char **i;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
            for (i = sp; *i != NULL; i++)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
                this->fileTree->AppendItem(item, wxString(*i, wxConvUTF8));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
        } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
        PHYSFS_freeList(sp);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
    } // else
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
    // Now fill in the filesystem...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    this->fsItem = this->fileTree->AppendItem(root, wxT("Filesystem"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    this->fillFileSystemTree("/", this->fsItem);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
    this->fileTree->Expand(this->fsItem);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
} // WxTestPhysfsFrame::rebuildTree
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
void WxTestPhysfsFrame::doInit(const char *argv0)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
    if (!this->err(PHYSFS_init(argv0)))
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
        ::wxMessageBox(wxT("PHYSFS_init() failed!"), wxT("wxTestPhysfs"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
    this->rebuildTree();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
} // WxTestPhysfsFrame::doInit
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
void WxTestPhysfsFrame::doDeinit()
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
    if (!this->err(PHYSFS_deinit()))
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
        ::wxMessageBox(wxT("PHYSFS_deinit() failed!"), wxT("wxTestPhysfs"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    this->rebuildTree();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
} // WxTestPhysfsFrame::doDeinit
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
void WxTestPhysfsFrame::onMenuInit(wxCommandEvent &evt)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    wxString argv0(wxGetApp().argv[0] == NULL ? wxT("") : wxGetApp().argv[0]);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    wxString str(wxGetTextFromUser(wxT("PHYSFS_init"),
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
                 wxT("argv[0]? (cancel for NULL)"), argv0));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
    char *cstr = str.IsEmpty() ? NULL : newutf8(str);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    this->doInit(cstr);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
    delete[] cstr;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
} // WxTestPhysfsFrame::onMenuInit
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
void WxTestPhysfsFrame::onMenuDeinit(wxCommandEvent &evt)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    this->doDeinit();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
} // WxTestPhysfsFrame::onMenuDeinit
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
void WxTestPhysfsFrame::onMenuAddArchive(wxCommandEvent &evt)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    wxString arc = wxFileSelector(wxT("Choose archive to add"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    if (!arc.IsEmpty())
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
        char *cstr = newutf8(arc);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
        // !!! FIXME: add to start/end?
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
        if (!this->err(PHYSFS_addToSearchPath(cstr, 1)))
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
            ::wxMessageBox(wxT("PHYSFS_addToSearchPath() failed!"), wxT("wxTestPhysfs"));
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
        delete[] cstr;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
        this->rebuildTree();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
    } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
} // WxTestPhysfsFrame::onMenuAddArchive
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
void WxTestPhysfsFrame::onMenuGetCDs(wxCommandEvent &evt)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
    this->rebuildTree();  // This will call PHYSFS_getCdRomDirs()...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
} // WxTestPhysfsFrame::onMenuGetCDs
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
void WxTestPhysfsFrame::onMenuPermitSymLinks(wxCommandEvent &evt)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
    PHYSFS_permitSymbolicLinks(evt.IsChecked() ? 1 : 0);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
    this->rebuildTree();
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
} // WxTestPhysfsFrame::onMenuPermitSymLinks
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
IMPLEMENT_APP(WxTestPhysfsApp)
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
bool WxTestPhysfsApp::OnInit()
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
{
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
    #if PLATFORM_MACOSX
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
    // This lets a stdio app become a GUI app. Otherwise, you won't get
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
    //  GUI events from the system and other things will fail to work.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
    // Putting the app in an application bundle does the same thing.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
    //  TransformProcessType() is a 10.3+ API. SetFrontProcess() is 10.0+.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
    if (TransformProcessType != NULL)  // check it as a weak symbol.
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
    {
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
        ProcessSerialNumber psn = { 0, kCurrentProcess };
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
        TransformProcessType(&psn, kProcessTransformToForegroundApplication);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
        SetFrontProcess(&psn);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    } // if
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
    #endif
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    this->mainWindow = new WxTestPhysfsFrame(this->argv[0]);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    this->mainWindow->Show(true);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    SetTopWindow(this->mainWindow);
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
    return true;
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
} // WxTestPhysfsApp::OnInit
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
// end of wxtest_physfs.cpp ...
6d65c5e0049a Added initial work on a wxWidgets-based test app.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486