github publish

This commit is contained in:
Ondrej Novak 2025-01-24 18:27:22 +01:00
commit 506e23bf32
542 changed files with 120675 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
*.user
*.old
*.XML
.svn
_UpgradeReport_Files
/Bin
/Debug

BIN
.vs/Skeldal/v17/.suo Normal file

Binary file not shown.

64
3DTEST/TEXTURAA.ASM Normal file
View file

@ -0,0 +1,64 @@
.model small
.386
DGROUP group _DATA
extrn _start_poss:word
extrn _end_poss:word
extrn _scr_max_x:dword
extrn _scr_next_line:dword
_TEXT segment byte public 'CODE' use32
assume CS:_TEXT
assume DS:DGROUP
public draw_flat_triangle_
draw_flat_triangle_:
dft_lp2:mov ebx,edi
movsx edx,_start_poss[esi*2]
lea edi,[ebx+edx*2]
cmp dx,_end_poss[esi*2]
jz dft_skpa
jl dft_dirr
std
cmp edx,0
js dft_skpa
cmp edx,_scr_max_x
jbe dft_drr1
mov edi,_scr_max_x
lea edi,[ebx+edi*2]
jmp dft_drr1
dft_dirr:cld
cmp edx,_scr_max_x
jg dft_skpa
cmp edx,0
jns dft_drr1
mov edi,ebx
dft_drr1:movsx edx,_end_poss[esi*2]
cmp edx,0
jns dft_dc1
xor edx,edx
jmp dft_dc2
dft_dc1:cmp edx,_scr_max_x
jna dft_dc2
mov edx,_scr_max_x
dft_dc2:shl edx,1
add edx,ebx
dft_lp1: stosw
cmp edi,edx
jnz dft_lp1
dft_skpa:
stosw
mov edi,_scr_next_line
lea edi,[ebx+edi]
inc esi
dec ecx
jnz dft_lp2
cld
ret
_TEXT ends
end

187
AdvMan/AdvMan.cpp Normal file
View file

@ -0,0 +1,187 @@
// AdvMan.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "AdvMan.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAdvManApp
BEGIN_MESSAGE_MAP(CAdvManApp, CWinApp)
//{{AFX_MSG_MAP(CAdvManApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdvManApp construction
CAdvManApp::CAdvManApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CAdvManApp object
CAdvManApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CAdvManApp initialization
extern "C"
{
#include "..\crashdump.h"
int GetExeVersion();
}
int GetExeVersion()
{
return 1;
}
BOOL CAdvManApp::InitInstance()
{
InitCrashDump();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Bredysoft"));
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
// create and load the frame with its resources
pFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);
// The one and only window has been initialized, so show and update it.
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAdvManApp message handlers
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CAdvManApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CAdvManApp message handlers
struct TestDlgInfo
{
MSG *msg;
BOOL found;
HWND exclude;
};
static BOOL WINAPI TestDlgWindows(HWND hWnd, LPARAM lParam)
{
TestDlgInfo *nfo=(TestDlgInfo *)lParam;
if (hWnd==nfo->exclude) return TRUE;
if (SendMessage(hWnd,WM_APP+9998,0,(LPARAM)nfo->msg) || IsDialogMessage(hWnd,nfo->msg))
{
nfo->found=TRUE;
return FALSE;
}
return TRUE;
}
BOOL CAdvManApp::PreTranslateMessage(MSG *pMsg)
{
TestDlgInfo nfo;
nfo.msg=pMsg;
nfo.found=FALSE;
nfo.exclude=*m_pMainWnd;
EnumThreadWindows(GetCurrentThreadId(),TestDlgWindows,(LPARAM)&nfo);
return nfo.found;
}

55
AdvMan/AdvMan.h Normal file
View file

@ -0,0 +1,55 @@
// AdvMan.h : main header file for the ADVMAN application
//
#if !defined(AFX_ADVMAN_H__A43CD3B3_508C_4DDB_B89C_50FE1291B8B9__INCLUDED_)
#define AFX_ADVMAN_H__A43CD3B3_508C_4DDB_B89C_50FE1291B8B9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CAdvManApp:
// See AdvMan.cpp for the implementation of this class
//
class CAdvManApp : public CWinApp
{
public:
CAdvManApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAdvManApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
public:
//{{AFX_MSG(CAdvManApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
virtual BOOL PreTranslateMessage(MSG *pMsg);
};
/////////////////////////////////////////////////////////////////////////////
extern CAdvManApp theApp;
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_ADVMAN_H__A43CD3B3_508C_4DDB_B89C_50FE1291B8B9__INCLUDED_)

569
AdvMan/AdvMan.rc Normal file
View file

@ -0,0 +1,569 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Czech resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CSY)
#ifdef _WIN32
LANGUAGE LANG_CZECH, SUBLANG_DEFAULT
#pragma code_page(1250)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\AdvMan.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDR_MAINFRAME BITMAP "res\\Toolbar.bmp"
IDR_TOOLEDITORY BITMAP "res\\editory.bmp"
IDR_PREKLADACE BITMAP "res\\prekladace.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Toolbar
//
IDR_MAINFRAME TOOLBAR 16, 16
BEGIN
BUTTON ID_FILE_NOVDOBRODRUST
BUTTON ID_FILE_NATIDOBRODRUSTV
SEPARATOR
BUTTON ID_NSTROJE_MAPEDIT
BUTTON ID_NSTROJE_TESTUJDOBRODRUSTV
SEPARATOR
BUTTON ID_APP_EXIT
SEPARATOR
BUTTON ID_APP_ABOUT
END
IDR_TOOLEDITORY TOOLBAR 16, 15
BEGIN
BUTTON ID_EDITORY_KOUZLATAB
BUTTON ID_EDITORY_POSTAVYTAB
BUTTON ID_EDITORY_DIALOGY
BUTTON ID_EDITORY_WEAPONSSCR
BUTTON ID_EDITORY_ITEMSPIC
BUTTON ID_EDITORY_ITEMSSCR
END
IDR_PREKLADACE TOOLBAR 16, 15
BEGIN
BUTTON ID_PEKLADAE_PELOKOUZLA
BUTTON ID_PEKLADAE_PELODIALOGY
BUTTON ID_PEKLADAE_PELOPOSTAVYTAB
END
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MAINFRAME MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "Nové dobrodružstí", ID_FILE_NOVDOBRODRUST
MENUITEM SEPARATOR
MENUITEM "Naèti dobrodružství", ID_FILE_NATIDOBRODRUSTV
MENUITEM "Znovu naèíst", ID_FILE_ZNOVUNAST
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
END
POPUP "Editory"
BEGIN
MENUITEM "KOUZLA.TAB", ID_EDITORY_KOUZLATAB
MENUITEM "POSTAVY.TAB", ID_EDITORY_POSTAVYTAB
MENUITEM "Dialogy", ID_EDITORY_DIALOGY
MENUITEM "ITEMS.SCR", ID_EDITORY_ITEMSSCR
MENUITEM "ITEMS.PIC", ID_EDITORY_ITEMSPIC
MENUITEM "WEAPONS.SCR", ID_EDITORY_WEAPONSSCR
MENUITEM "Soubor ADV", ID_EDITORY_SOUBORADV
END
POPUP "Pøekladaèe"
BEGIN
MENUITEM "Pøelož kouzla", ID_PEKLADAE_PELOKOUZLA
MENUITEM "Pøelož dialogy", ID_PEKLADAE_PELODIALOGY
MENUITEM "Pøelož POSTAVY.TAB", ID_PEKLADAE_PELOPOSTAVYTAB
END
POPUP "Nástroje"
BEGIN
MENUITEM "MapEdit", ID_NSTROJE_MAPEDIT
MENUITEM "Testuj dobrodružství", ID_NSTROJE_TESTUJDOBRODRUSTV
MENUITEM SEPARATOR
MENUITEM "Tvùrce podlah", ID_NSTROJE_TVRCEPODLAH
MENUITEM "Tvùrce palet pro nestvùry", ID_NSTROJE_TVRCEPALETPRONESTVRY
MENUITEM "Tvùrce ikon pro pøedmìty", ID_NSTROJE_TVRCEIKONPROPEDMTY
MENUITEM "Èteèka DDL souborù", ID_NSTROJE_TEKADDLSOUBOR
MENUITEM SEPARATOR
MENUITEM "Exportuj dobrodružství", ID_NSTROJE_EXPORTUJDOBRODRUSTV
END
POPUP "&View"
BEGIN
MENUITEM "Hlavní toolbar", ID_VIEW_TOOLBAR
MENUITEM "Pøekladaèe", ID_VIEW_PREKLADACE
MENUITEM "Editory", 32810
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
END
POPUP "&Help"
BEGIN
MENUITEM "&About AdvMan...", ID_APP_ABOUT
END
END
IDR_EDITORMENU MENU
BEGIN
POPUP "Soubor"
BEGIN
MENUITEM "Uložit", IDOK
MENUITEM SEPARATOR
MENUITEM "Konec", IDCANCEL
END
POPUP "Úpravy"
BEGIN
MENUITEM "Zpìt", ID_PRAVY_UNDO
MENUITEM SEPARATOR
MENUITEM "Kopírovat", ID_UPRAVY_COPY
MENUITEM "Vyjmout", ID_UPRAVY_VYJMOUT
MENUITEM "Vložit", ID_UPRAVY_VLOZIT
MENUITEM "Vymazat", ID_UPRAVY_VYMAZAT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_NOVEDOBR DIALOGEX 0, 0, 234, 297
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Založit nové dobrodružství"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
LTEXT "Jméno nového dobrodružství",IDC_STATIC,7,7,92,8
EDITTEXT IDC_JMENO,7,18,159,12,ES_AUTOHSCROLL | WS_GROUP
GROUPBOX "Vyber organizaci projektu",IDC_STATIC,7,36,162,60,
WS_GROUP
CONTROL "Nová organizace (doporuèeno)",IDC_ORGANIZACE,"Button",
BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,15,55,114,10
CONTROL "Pùvodní DOSová organizace (kompatibilní)",IDC_RADIO2,
"Button",BS_AUTORADIOBUTTON,15,66,152,10
CONTROL "Vše v jedné složce (malé projeky)",IDC_RADIO3,"Button",
BS_AUTORADIOBUTTON,15,77,121,10
GROUPBOX "Do nového projektu vložit",IDC_STATIC,7,98,162,82,
WS_GROUP
CONTROL "Také soubory pro editaci kouzel",IDC_KOUZLA,"Button",
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,111,117,10
CONTROL "Také soubory pro editaci dialogù",IDC_DIALOGY,"Button",
BS_AUTOCHECKBOX,15,123,119,10
CONTROL "Také definice grafiky originální hry",IDC_DEFINICE,
"Button",BS_AUTOCHECKBOX,15,135,123,10
CONTROL "Také všechny mapy z originální hry",IDC_MAPY,"Button",
BS_AUTOCHECKBOX,15,147,127,10
GROUPBOX "Startovní mapa",IDC_STATIC,7,183,161,29,WS_GROUP
EDITTEXT IDC_STARTMAP,16,193,145,12,ES_AUTOHSCROLL | WS_GROUP
GROUPBOX "Poèet èlenù družiny",IDC_STATIC,7,214,161,42,WS_GROUP
LTEXT "Nejménì",IDC_STATIC,15,228,29,8
LTEXT "Nejvíce",IDC_STATIC,15,242,26,8
EDITTEXT IDC_MINPOSTAV,53,226,16,12,ES_MULTILINE | WS_GROUP
EDITTEXT IDC_MAXPOSTAV,53,240,16,12,ES_MULTILINE | WS_GROUP
DEFPUSHBUTTON "OK",IDOK,177,7,50,14,WS_GROUP
PUSHBUTTON "Storno",IDCANCEL,177,24,50,14,NOT WS_TABSTOP
CONTROL "Také originální dialogy",IDC_ORIGDLGS,"Button",
BS_AUTOCHECKBOX,15,159,87,10
END
IDD_TEXTEDITOR DIALOGEX 0, 0, 599, 412
STYLE DS_SETFONT | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP |
WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Textový editor"
MENU IDR_EDITORMENU
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "Uložit (Ctrl+S)",IDOK,540,397,58,14
EDITTEXT IDC_EDIT,44,0,553,395,ES_MULTILINE | ES_AUTOVSCROLL |
ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER |
WS_VSCROLL | WS_HSCROLL,WS_EX_STATICEDGE
END
IDD_DIALOGY DIALOGEX 0, 0, 334, 202
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialogy"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
PUSHBUTTON "Zavøít",IDCANCEL,267,24,60,14
PUSHBUTTON "Upravit dialog",IDC_EDIT,267,68,60,14
PUSHBUTTON "Pøidat dialog",IDC_ADD,267,52,60,14
PUSHBUTTON "Vymazat dialog",IDC_DELETE,267,85,60,14
CONTROL "List1",IDC_DLGLIST,"SysListView32",LVS_REPORT |
LVS_SHOWSELALWAYS | LVS_EDITLABELS | WS_BORDER |
WS_TABSTOP,7,7,256,188
PUSHBUTTON "Obnovit",IDC_RESCAN,267,181,60,14
DEFPUSHBUTTON "OK",IDOK,267,7,60,14
END
IDD_NOVYDIALOG DIALOG 0, 0, 214, 105
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Nový dialog"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,157,67,50,14
PUSHBUTTON "Cancel",IDCANCEL,157,84,50,14
LTEXT "Popis dialogu:",IDC_STATIC,7,7,45,8
EDITTEXT IDC_POPIS,7,18,200,12,ES_AUTOHSCROLL
LTEXT "Jméno souboru dialogu bez pøípony (.dlg) - 8 znakù",
IDC_STATIC,7,32,162,8
COMBOBOX IDC_JMENO,7,43,73,61,CBS_DROPDOWN | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
LTEXT "Èislo dialogu:",IDC_STATIC,7,60,42,8
LTEXT "Uplatní se pouze pro novì založený dialog",IDC_STATIC,7,
89,134,8
COMBOBOX IDC_CISLO,7,72,33,105,CBS_DROPDOWN | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_NOVEDOBR, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 227
TOPMARGIN, 7
BOTTOMMARGIN, 290
END
IDD_TEXTEDITOR, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 592
TOPMARGIN, 7
BOTTOMMARGIN, 405
END
IDD_DIALOGY, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 327
TOPMARGIN, 7
BOTTOMMARGIN, 195
END
IDD_NOVYDIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 207
TOPMARGIN, 7
BOTTOMMARGIN, 98
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_NOTEPADICON ICON "idc_note.ico"
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDR_MAINFRAME "Adventure Manager"
IDS_NOVEDOBRODRUZSTVIDOKONCENO
"Prùvodce novým dobrodružstvím dokonèil všechny úkoly.\r\n\r\nPokud se zobrazila nìjaká chyba, bude nutné po opravì chyby pøíkaz opakovat, jinak nebude dobrodružství hratelné."
IDS_ADVFILTER "Dobrodružství Skeldalu|*.adv|Všechny soubory|*.*||"
IDS_CHYBAPRICTENI "Chyba pøi ètení souboru dobrodružství"
IDS_MAINFRAMETITLE "%s - Adventure Manager "
IDS_UNTITLED "Nepojmenované.ADV"
IDS_CANNOTEXECUTE "Nemohu spustit aplikaci '%1'"
IDS_NEMOHUNAJITNICOD "Pozor! Nemohu najít následující soubor(y):\r\n\r\n%1\r\n\r\nChybìjící soubory mohou zpùsobit, že dobrodružství nebude možné hrát."
IDS_EDITADVWARN "Pozor! Zmìny v souboru ADV se neprojeví ihned. Po uložení nechte znovu naèíst dobrodružství pomocí funkce Soubor -> Znovu naèíst."
IDS_DLGNAME "Jméno"
IDS_DLGDESC "Popis"
IDS_DLGID "ID"
IDS_UNABLETOSAVEDIALOGYDLG
"Nemohu uložit soubor DIALOGY.DLG. Nastala nìjaká chyba."
IDS_NODESC "<Bez Popisu>"
END
STRINGTABLE
BEGIN
AFX_IDS_APP_TITLE "AdvMan"
AFX_IDS_IDLEMESSAGE "Ready"
END
STRINGTABLE
BEGIN
ID_INDICATOR_EXT "EXT"
ID_INDICATOR_CAPS "CAP"
ID_INDICATOR_NUM "NUM"
ID_INDICATOR_SCRL "SCRL"
ID_INDICATOR_OVR "OVR"
ID_INDICATOR_REC "REC"
END
STRINGTABLE
BEGIN
ID_APP_ABOUT "Display program information, version number and copyright\nAbout"
ID_APP_EXIT "Quit the application; prompts to save documents\nExit"
END
STRINGTABLE
BEGIN
ID_NEXT_PANE "Switch to the next window pane\nNext Pane"
ID_PREV_PANE "Switch back to the previous window pane\nPrevious Pane"
END
STRINGTABLE
BEGIN
ID_WINDOW_SPLIT "Split the active window into panes\nSplit"
END
STRINGTABLE
BEGIN
ID_EDIT_CLEAR "Erase the selection\nErase"
ID_EDIT_CLEAR_ALL "Erase everything\nErase All"
ID_EDIT_COPY "Copy the selection and put it on the Clipboard\nCopy"
ID_EDIT_CUT "Cut the selection and put it on the Clipboard\nCut"
ID_EDIT_FIND "Find the specified text\nFind"
ID_EDIT_PASTE "Insert Clipboard contents\nPaste"
ID_EDIT_REPEAT "Repeat the last action\nRepeat"
ID_EDIT_REPLACE "Replace specific text with different text\nReplace"
ID_EDIT_SELECT_ALL "Select the entire document\nSelect All"
ID_EDIT_UNDO "Undo the last action\nUndo"
ID_EDIT_REDO "Redo the previously undone action\nRedo"
END
STRINGTABLE
BEGIN
ID_VIEW_TOOLBAR "Show or hide the toolbar\nToggle ToolBar"
ID_VIEW_STATUS_BAR "Show or hide the status bar\nToggle StatusBar"
END
STRINGTABLE
BEGIN
AFX_IDS_SCSIZE "Change the window size"
AFX_IDS_SCMOVE "Change the window position"
AFX_IDS_SCMINIMIZE "Reduce the window to an icon"
AFX_IDS_SCMAXIMIZE "Enlarge the window to full size"
AFX_IDS_SCNEXTWINDOW "Switch to the next document window"
AFX_IDS_SCPREVWINDOW "Switch to the previous document window"
AFX_IDS_SCCLOSE "Close the active window and prompts to save the documents"
END
STRINGTABLE
BEGIN
AFX_IDS_SCRESTORE "Restore the window to normal size"
AFX_IDS_SCTASKLIST "Activate Task List"
END
#endif // Czech resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About AdvMan"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "AdvMan Version 1.0",IDC_STATIC,40,10,119,8,SS_NOPREFIX
LTEXT "Copyright (C) 2005",IDC_STATIC,40,25,119,8
DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\AdvMan.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAINFRAME ACCELERATORS
BEGIN
"C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT
VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT, NOINVERT
VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT
VK_F6, ID_NEXT_PANE, VIRTKEY, NOINVERT
VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT, NOINVERT
VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT, NOINVERT
"X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "FileDescription", "AdvMan MFC Application"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "AdvMan"
VALUE "LegalCopyright", "Copyright (C) 2005"
VALUE "OriginalFilename", "AdvMan.EXE"
VALUE "ProductName", "AdvMan Application"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\AdvMan.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

21
AdvMan/AdvMan.sln Normal file
View file

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdvMan", "AdvMan.vcproj", "{D38E31E6-CC5E-4C25-B966-85BF48E8C53E}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{D38E31E6-CC5E-4C25-B966-85BF48E8C53E}.Debug.ActiveCfg = Debug|Win32
{D38E31E6-CC5E-4C25-B966-85BF48E8C53E}.Debug.Build.0 = Debug|Win32
{D38E31E6-CC5E-4C25-B966-85BF48E8C53E}.Release.ActiveCfg = Release|Win32
{D38E31E6-CC5E-4C25-B966-85BF48E8C53E}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

525
AdvMan/AdvMan.vcproj Normal file
View file

@ -0,0 +1,525 @@
<?xml version="1.0" encoding="windows-1250"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="AdvMan"
SccProjectName=""
SccAuxPath=""
SccLocalPath=""
SccProvider=""
Keyword="MFCProj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="1"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories=".\,..\libs"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Release/AdvMan.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Release/AdvMan.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Release/AdvMan.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Release/AdvMan.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1029"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="1"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\,..\libs"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Debug/AdvMan.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Debug/AdvMan.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/AdvMan.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/AdvMan.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1029"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="AdvMan.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="AdvMan.rc">
</File>
<File
RelativePath="ChildView.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\crashdump.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath="..\cztable.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
UsePrecompiledHeader="0"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="DlgDialogy.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="DlgNoveDobr.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="DlgNovyDialog.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\mapedit\editor.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
UsePrecompiledHeader="0"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\LIBS\INICFG.C">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
UsePrecompiledHeader="0"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="MainFrm.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="Pathname.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
UsePrecompiledHeader="0"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="StdAfx.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
UsePrecompiledHeader="1"
BrowseInformation="1"/>
</FileConfiguration>
</File>
<File
RelativePath="..\LIBS\STRLITE.C">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
UsePrecompiledHeader="0"
BrowseInformation="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath="AdvMan.h">
</File>
<File
RelativePath="bgraph2dx.h">
</File>
<File
RelativePath="ChildView.h">
</File>
<File
RelativePath="..\crashdump.h">
</File>
<File
RelativePath="..\cztable.h">
</File>
<File
RelativePath="DlgDialogy.h">
</File>
<File
RelativePath="DlgNoveDobr.h">
</File>
<File
RelativePath="DlgNovyDialog.h">
</File>
<File
RelativePath="..\mapedit\editor.h">
</File>
<File
RelativePath="..\LIBS\INICFG.H">
</File>
<File
RelativePath="MainFrm.h">
</File>
<File
RelativePath="mem.h">
</File>
<File
RelativePath="..\LIBS\MEMMAN.H">
</File>
<File
RelativePath="Pathname.h">
</File>
<File
RelativePath="Resource.h">
</File>
<File
RelativePath="skeldal_win.h">
</File>
<File
RelativePath="StdAfx.h">
</File>
<File
RelativePath="..\LIBS\STRLITE.H">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File
RelativePath="res\AdvMan.ico">
</File>
<File
RelativePath="res\AdvMan.rc2">
</File>
<File
RelativePath=".\res\editory.bmp">
</File>
<File
RelativePath="idc_note.ico">
</File>
<File
RelativePath=".\res\prekladace.bmp">
</File>
<File
RelativePath="res\Toolbar.bmp">
</File>
<File
RelativePath=".\res\toolbar1.bmp">
</File>
</Filter>
<File
RelativePath="ReadMe.txt">
</File>
</Files>
<Globals>
<Global
Name="RESOURCE_FILE"
Value="AdvMan.rc"/>
</Globals>
</VisualStudioProject>

57
AdvMan/ChildView.cpp Normal file
View file

@ -0,0 +1,57 @@
// ChildView.cpp : implementation of the CChildView class
//
#include "stdafx.h"
#include "AdvMan.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChildView
CChildView::CChildView()
{
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
}

51
AdvMan/ChildView.h Normal file
View file

@ -0,0 +1,51 @@
// ChildView.h : interface of the CChildView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_CHILDVIEW_H__C7E216F0_6DED_46F2_9E4F_0F71719D08CA__INCLUDED_)
#define AFX_CHILDVIEW_H__C7E216F0_6DED_46F2_9E4F_0F71719D08CA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CChildView window
class CChildView : public CWnd
{
// Construction
public:
CChildView();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CChildView)
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CChildView();
// Generated message map functions
protected:
//{{AFX_MSG(CChildView)
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CHILDVIEW_H__C7E216F0_6DED_46F2_9E4F_0F71719D08CA__INCLUDED_)

264
AdvMan/DlgDialogy.cpp Normal file
View file

@ -0,0 +1,264 @@
// DlgDialogy.cpp : implementation file
//
#include "stdafx.h"
#include "AdvMan.h"
#include "DlgDialogy.h"
#include "../cztable.h"
#include "MainFrm.h"
#include "DlgNovyDialog.h"
#include <io.h>
#include ".\dlgdialogy.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgDialogy dialog
DlgDialogy::DlgDialogy(CWnd* pParent /*=NULL*/)
: CDialog(DlgDialogy::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgDialogy)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void DlgDialogy::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgDialogy)
DDX_Control(pDX, IDC_DLGLIST, wList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgDialogy, CDialog)
//{{AFX_MSG_MAP(DlgDialogy)
ON_BN_CLICKED(IDC_RESCAN, OnRescan)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_EDIT, OnEdit)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_DLGLIST, OnColumnclickDlglist)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_NOTIFY(NM_DBLCLK, IDC_DLGLIST, OnNMDblclkDlglist)
//}}AFX_MSG_MAP
ON_NOTIFY(LVN_ENDLABELEDIT, IDC_DLGLIST, OnLvnEndlabeleditDlglist)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgDialogy message handlers
BOOL DlgDialogy::OnInitDialog()
{
CDialog::OnInitDialog();
wList.InsertColumn(0,CString(MAKEINTRESOURCE(IDS_DLGDESC)),LVCFMT_LEFT,200,0);
wList.InsertColumn(1,CString(MAKEINTRESOURCE(IDS_DLGNAME)),LVCFMT_LEFT,100,1);
wList.InsertColumn(2,CString(MAKEINTRESOURCE(IDS_DLGID)),LVCFMT_CENTER,30,2);
ListView_SetExtendedListViewStyleEx(wList,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
OnRescan();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
int DlgDialogy::GetDialogID(const char *name)
{
Pathname dialogPath=_dlgpath;
dialogPath.SetFilename(name);
FILE *f=fopen(dialogPath,"r");
if (f==0) return -1;
int id;
char dialog[40];
if (fscanf(f," %40[^\r\n\t (] ( %d )",dialog,&id)==2)
{
if (stricmp(dialog,"DIALOG")==0)
{
fclose(f);
return id;
}
}
fclose(f);
return -1;
}
void DlgDialogy::LoadDialogyDlg()
{
FILE *f=fopen(_dlgpath,"r");
if (f==0) return;
int p=0;
while (!feof(f))
{
char name[80];
char desc[256];
name[0]=0;
desc[0]=0;
fscanf(f,"%80s",name);
fscanf(f," %250[^\r\n]",desc);
kamenik2windows(name,strlen(name),name);
kamenik2windows(desc,strlen(desc),desc);
int row;
if (name[0]!=0 || desc[0]!=0)
{
row=wList.InsertItem(p,desc,0);
wList.SetItemText(row,1,name);
int dlgId=GetDialogID(name);
wList.SetItemText(row,2,itoa(dlgId,desc,10));
p++;
}
}
fclose(f);
}
void DlgDialogy::OnRescan()
{
wList.DeleteAllItems();
LoadDialogyDlg();
}
void DlgDialogy::OnDelete()
{
int w;
while ((w=wList.GetNextItem(-1,LVNI_SELECTED))!=-1)
{
wList.DeleteItem(w);
}
}
void DlgDialogy::OnEdit()
{
CString name;
int w=-1;
while ((w=wList.GetNextItem(w,LVNI_SELECTED))!=-1)
{
name=wList.GetItemText(w,1);
Pathname editName=_dlgpath;
editName.SetFilename(name);
_mainFrame->OpenEditor(editName);
}
}
void DlgDialogy::OnOK()
{
FILE *f=fopen(_dlgpath,"w");
if (f==0)
{
AfxMessageBox(IDS_UNABLETOSAVEDIALOGYDLG,MB_ICONEXCLAMATION);
return;
}
for (int i=0,cnt=wList.GetItemCount();i<cnt;i++)
{
CString name=wList.GetItemText(i,1);
CString desc=wList.GetItemText(i,0);
windows2kamenik(name,name.GetLength(),name.LockBuffer());
windows2kamenik(desc,desc.GetLength(),desc.LockBuffer());
name.UnlockBuffer();
desc.UnlockBuffer();
if (desc.Trim().GetLength()==0)
desc.LoadString(IDS_NODESC);
if (name.Trim().GetLength()) fprintf(f,"%s %s\n",name.GetString(),desc.GetString());
}
fclose(f);
CDialog::OnOK();
}
void DlgDialogy::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void DlgDialogy::OnColumnclickDlglist(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
for (int i=0,cnt=wList.GetItemCount();i<cnt;i++)
{
wList.SetItemData(i,i);
}
_sortItem=pNMListView->iSubItem;
wList.SortItems(CompareFunc,(DWORD)this);
*pResult = 0;
}
int DlgDialogy::CompareItems(int item1, int item2)
{
switch (_sortItem)
{
case 0:
{
CString a=wList.GetItemText(item1,0);
CString b=wList.GetItemText(item2,0);
return stricmp(a,b);
}
case 1:
{
CString a=wList.GetItemText(item1,1);
CString b=wList.GetItemText(item2,1);
return stricmp(a,b);
}
case 2:
{
char buff[20];
int a,b;
wList.GetItemText(item1,2,buff,20);a=atoi(buff);
wList.GetItemText(item2,2,buff,20);b=atoi(buff);
return (a>b)-(a<b);
}
}
return 0;
}
void DlgDialogy::OnAdd()
{
DlgNovyDialog nw;
nw.dlgSource=this->_dlgpath;
nw.sourceLst=&wList;
if (nw.DoModal()==IDOK)
{
int p=wList.InsertItem(wList.GetItemCount(),nw.vPopis);
Pathname dlgName=_dlgpath;
dlgName.SetFiletitle(nw.vJmeno);
dlgName.SetExtension(".dlg");
wList.SetItemText(p,1,dlgName.GetFilename());
if (_access(dlgName,0)!=0)
{
FILE *f=fopen(dlgName,"w");
fprintf(f,"DIALOG(%d)\n",nw.vCislo);
fprintf(f,"{\nPICTURE (\"SCREEN\")\nDESC (\"Popis\")\nSTANDARD (1)\n}\n\nSENTENCE (1,0)\n{\n\n}");
fclose(f);
}
int num=GetDialogID(dlgName.GetFilename());
char buff[20];
wList.SetItemText(p,2,itoa(num,buff,10));
}
}
void DlgDialogy::OnNMDblclkDlglist(NMHDR *pNMHDR, LRESULT *pResult)
{
OnEdit();
*pResult = 0;
}
void DlgDialogy::OnLvnEndlabeleditDlglist(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 1;
}

76
AdvMan/DlgDialogy.h Normal file
View file

@ -0,0 +1,76 @@
#if !defined(AFX_DLGDIALOGY_H__E47269D5_6849_42F5_AF6F_32EEEE32104D__INCLUDED_)
#define AFX_DLGDIALOGY_H__E47269D5_6849_42F5_AF6F_32EEEE32104D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgDialogy.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// DlgDialogy dialog
#define MAXDIALOGY 240
class CMainFrame;
class DlgDialogy : public CDialog
{
// Construction
public:
void LoadDialogyDlg();
DlgDialogy(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(DlgDialogy)
enum { IDD = IDD_DIALOGY };
CListCtrl wList;
//}}AFX_DATA
Pathname _dlgpath;
CMainFrame *_mainFrame;
int _sortItem;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(DlgDialogy)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(DlgDialogy)
virtual BOOL OnInitDialog();
afx_msg void OnRescan();
afx_msg void OnDelete();
afx_msg void OnEdit();
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnColumnclickDlglist(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnAdd();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
int GetDialogID(const char *name);
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
DlgDialogy *self=(DlgDialogy *)lParamSort;
return self->CompareItems(lParam1,lParam2);
}
int CompareItems(int item1, int item2);
public:
afx_msg void OnNMDblclkDlglist(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnLvnEndlabeleditDlglist(NMHDR *pNMHDR, LRESULT *pResult);
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLGDIALOGY_H__E47269D5_6849_42F5_AF6F_32EEEE32104D__INCLUDED_)

83
AdvMan/DlgNoveDobr.cpp Normal file
View file

@ -0,0 +1,83 @@
// DlgNoveDobr.cpp : implementation file
//
#include "stdafx.h"
#include "AdvMan.h"
#include "DlgNoveDobr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgNoveDobr dialog
DlgNoveDobr::DlgNoveDobr(CWnd* pParent /*=NULL*/)
: CDialog(DlgNoveDobr::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgNoveDobr)
vJmeno = _T("");
vKouzla = TRUE;
vMapy = FALSE;
vDialogy = TRUE;
vDefinice = FALSE;
vOrganizace = 0;
vStartMap = _T("start.map");
vMaxPostav = 3;
vMinPostav = 3;
//}}AFX_DATA_INIT
}
void DlgNoveDobr::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgNoveDobr)
DDX_Text(pDX, IDC_JMENO, vJmeno);
DDX_Check(pDX, IDC_KOUZLA, vKouzla);
DDX_Check(pDX, IDC_MAPY, vMapy);
DDX_Check(pDX, IDC_DIALOGY, vDialogy);
DDX_Check(pDX, IDC_DEFINICE, vDefinice);
DDX_Radio(pDX, IDC_ORGANIZACE, vOrganizace);
DDX_Text(pDX, IDC_STARTMAP, vStartMap);
DDX_Check(pDX, IDC_ORIGDLGS, vDialogyDlg);
DDV_MaxChars(pDX, vStartMap, 12);
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_MINPOSTAV, vMinPostav);
DDV_MinMaxUInt(pDX, vMinPostav, 1, 6);
DDX_Text(pDX, IDC_MAXPOSTAV, vMaxPostav);
DDV_MinMaxUInt(pDX, vMaxPostav, vMinPostav, 6);
}
BEGIN_MESSAGE_MAP(DlgNoveDobr, CDialog)
//{{AFX_MSG_MAP(DlgNoveDobr)
ON_EN_CHANGE(IDC_JMENO, OnChangeJmeno)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgNoveDobr message handlers
void DlgNoveDobr::DialogRules()
{
GetDlgItem(IDOK)->EnableWindow(GetDlgItem(IDC_JMENO)->GetWindowTextLength());
}
BOOL DlgNoveDobr::OnInitDialog()
{
CDialog::OnInitDialog();
DialogRules();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void DlgNoveDobr::OnChangeJmeno()
{
DialogRules();
}

57
AdvMan/DlgNoveDobr.h Normal file
View file

@ -0,0 +1,57 @@
#if !defined(AFX_DLGNOVEDOBR_H__410472E5_5BCF_4CE8_8FE3_10693C0F05F7__INCLUDED_)
#define AFX_DLGNOVEDOBR_H__410472E5_5BCF_4CE8_8FE3_10693C0F05F7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgNoveDobr.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// DlgNoveDobr dialog
class DlgNoveDobr : public CDialog
{
// Construction
public:
void DialogRules();
DlgNoveDobr(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(DlgNoveDobr)
enum { IDD = IDD_NOVEDOBR };
CString vJmeno;
BOOL vKouzla;
BOOL vMapy;
BOOL vDialogy;
BOOL vDefinice;
BOOL vDialogyDlg;
int vOrganizace;
CString vStartMap;
UINT vMaxPostav;
UINT vMinPostav;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(DlgNoveDobr)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(DlgNoveDobr)
virtual BOOL OnInitDialog();
afx_msg void OnChangeJmeno();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLGNOVEDOBR_H__410472E5_5BCF_4CE8_8FE3_10693C0F05F7__INCLUDED_)

127
AdvMan/DlgNovyDialog.cpp Normal file
View file

@ -0,0 +1,127 @@
// DlgNovyDialog.cpp : implementation file
//
#include "stdafx.h"
#include "AdvMan.h"
#include "DlgNovyDialog.h"
#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgNovyDialog dialog
DlgNovyDialog::DlgNovyDialog(CWnd* pParent /*=NULL*/)
: CDialog(DlgNovyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgNovyDialog)
vCislo = 0;
vJmeno = _T("");
vPopis = _T("");
//}}AFX_DATA_INIT
}
void DlgNovyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgNovyDialog)
DDX_Control(pDX, IDC_CISLO, wCislo);
DDX_Control(pDX, IDC_JMENO, wJmeno);
DDX_Text(pDX, IDC_CISLO, vCislo);
DDV_MinMaxInt(pDX, vCislo, 1, 254);
DDX_CBString(pDX, IDC_JMENO, vJmeno);
DDV_MaxChars(pDX, vJmeno, 8);
DDX_Text(pDX, IDC_POPIS, vPopis);
DDV_MaxChars(pDX, vPopis, 50);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgNovyDialog, CDialog)
//{{AFX_MSG_MAP(DlgNovyDialog)
ON_CBN_EDITCHANGE(IDC_JMENO, OnEditchangeJmeno)
ON_CBN_SELENDOK(IDC_JMENO, OnSelendokJmeno)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgNovyDialog message handlers
BOOL DlgNovyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
bool idlist[256];
memset(idlist,0,sizeof(idlist));
dlgSource.SetFilename("*.dlg");
CFileFind fnd;
BOOL next;
if (fnd.FindFile(dlgSource)) do
{
next=fnd.FindNextFile();
CString name=fnd.GetFileTitle();
name.MakeLower();
wJmeno.AddString(name);
}while (next);
int i,cnt;
for (i=0,cnt=sourceLst->GetItemCount();i<cnt;i++)
{
CString name=sourceLst->GetItemText(i,1);
dlgSource.SetFilename(name);
name=dlgSource.GetTitle();
name.MakeLower();
int p=wJmeno.FindStringExact(-1,name);
if (p!=-1) wJmeno.DeleteString(p);
name=sourceLst->GetItemText(i,2);
p=atoi(name);
if (p>=0 && p<256) idlist[p]=true;
}
bool x=true;
for (i=1;i<254;i++) if (!idlist[i])
{
char buff[50];
sprintf(buff,"%3d",i);
wCislo.AddString(buff);
if (x)
{
wCislo.SetWindowText(buff);
x=false;
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void DlgNovyDialog::DialogRules()
{
BOOL ok=wJmeno.GetWindowTextLength() && wCislo.GetWindowTextLength();
GetDlgItem(IDOK)->EnableWindow(ok);
CString name;
wJmeno.GetWindowText(name);
dlgSource.SetFiletitle(name);
wCislo.EnableWindow(access(dlgSource,0)==-1);
}
void DlgNovyDialog::OnEditchangeJmeno()
{
DialogRules();
}
void DlgNovyDialog::OnSelendokJmeno()
{
int p=wJmeno.GetCurSel();
CString z;
wJmeno.GetLBText(p,z);
wJmeno.SetWindowText(z);
DialogRules();
}

57
AdvMan/DlgNovyDialog.h Normal file
View file

@ -0,0 +1,57 @@
#if !defined(AFX_DLGNOVYDIALOG_H__00136ADF_E2C6_4081_83AB_D5110EE43612__INCLUDED_)
#define AFX_DLGNOVYDIALOG_H__00136ADF_E2C6_4081_83AB_D5110EE43612__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgNovyDialog.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// DlgNovyDialog dialog
class DlgDialogy;
class DlgNovyDialog : public CDialog
{
// Construction
public:
void DialogRules();
DlgNovyDialog(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(DlgNovyDialog)
enum { IDD = IDD_NOVYDIALOG };
CComboBox wCislo;
CComboBox wJmeno;
int vCislo;
CString vJmeno;
CString vPopis;
//}}AFX_DATA
CListCtrl *sourceLst;
Pathname dlgSource;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(DlgNovyDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(DlgNovyDialog)
virtual BOOL OnInitDialog();
afx_msg void OnEditchangeJmeno();
afx_msg void OnSelendokJmeno();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLGNOVYDIALOG_H__00136ADF_E2C6_4081_83AB_D5110EE43612__INCLUDED_)

0
AdvMan/FCS_tasker.h Normal file
View file

0
AdvMan/FS_tasker.h Normal file
View file

677
AdvMan/MainFrm.cpp Normal file
View file

@ -0,0 +1,677 @@
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "AdvMan.h"
#include "..\cztable.h"
#include "MainFrm.h"
#include "DlgDialogy.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_WM_INITMENUPOPUP()
ON_COMMAND(ID_FILE_NOVDOBRODRUST, OnFileNovdobrodrust)
ON_COMMAND(ID_FILE_NATIDOBRODRUSTV, OnFileNatidobrodrustv)
ON_COMMAND(ID_EDITORY_KOUZLATAB, OnEditoryKouzlatab)
ON_COMMAND(ID_EDITORY_POSTAVYTAB, OnEditoryPostavytab)
ON_COMMAND(ID_EDITORY_ITEMSSCR, OnEditoryItemsscr)
ON_COMMAND(ID_EDITORY_ITEMSPIC, OnEditoryItemspic)
ON_COMMAND(ID_EDITORY_WEAPONSSCR, OnEditoryWeaponsscr)
ON_WM_DESTROY()
ON_COMMAND(ID_PEKLADAE_PELOKOUZLA, OnPekladaePelokouzla)
ON_COMMAND(ID_PEKLADAE_PELODIALOGY, OnPekladaePelodialogy)
ON_COMMAND(ID_PEKLADAE_PELOPOSTAVYTAB, OnPekladaePelopostavytab)
ON_COMMAND(ID_NSTROJE_MAPEDIT, OnNstrojeMapedit)
ON_COMMAND(ID_NSTROJE_TESTUJDOBRODRUSTV, OnNstrojeTestujdobrodrustv)
ON_COMMAND(ID_NSTROJE_TVRCEPODLAH, OnNstrojeTvrcepodlah)
ON_COMMAND(ID_NSTROJE_TVRCEPALETPRONESTVRY, OnNstrojeTvrcepaletpronestvry)
ON_COMMAND(ID_NSTROJE_TVRCEIKONPROPEDMTY, OnNstrojeTvrceikonpropedmty)
ON_COMMAND(ID_EDITORY_SOUBORADV, OnEditorySouboradv)
ON_COMMAND(ID_FILE_ZNOVUNAST, OnFileZnovunast)
ON_UPDATE_COMMAND_UI(ID_FILE_ZNOVUNAST, OnUpdateFileZnovunast)
ON_COMMAND(ID_EDITORY_DIALOGY, OnEditoryDialogy)
ON_COMMAND_EX(ID_VIEW_EDITORY,OnBarCheck)
ON_COMMAND_EX(ID_VIEW_PREKLADACE,OnBarCheck)
ON_UPDATE_COMMAND_UI(ID_VIEW_EDITORY,OnUpdateControlBarMenu)
ON_UPDATE_COMMAND_UI(ID_VIEW_PREKLADACE,OnUpdateControlBarMenu)
ON_UPDATE_COMMAND_UI_RANGE(ID_EDITORY_KOUZLATAB,ID_EDITORY_WEAPONSSCR,OnUpdateEditory)
ON_UPDATE_COMMAND_UI_RANGE(ID_PEKLADAE_PELOKOUZLA,ID_PEKLADAE_PELOPOSTAVYTAB,OnUpdateEditory)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// create a view to occupy the client area of the frame
if (!m_wndView.Create(ES_READONLY|WS_VISIBLE|WS_CHILD|ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL|WS_VSCROLL|WS_HSCROLL,CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST))
{
TRACE0("Failed to create view window\n");
return -1;
}
if (!m_wndToolBar.CreateEx(this, TBSTYLE_BUTTON, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY |BTNS_AUTOSIZE | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndEditoryBar.CreateEx(this, TBSTYLE_BUTTON, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY |BTNS_AUTOSIZE | CBRS_SIZE_DYNAMIC,CRect(0,0,0,0),ID_VIEW_EDITORY) ||
!m_wndEditoryBar.LoadToolBar(IDR_TOOLEDITORY))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndPrekladaceBar.CreateEx(this, TBSTYLE_BUTTON, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY |BTNS_AUTOSIZE | CBRS_SIZE_DYNAMIC,CRect(0,0,0,0),ID_VIEW_PREKLADACE) ||
!m_wndPrekladaceBar.LoadToolBar(IDR_PREKLADACE))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
ShowWindow(SW_SHOW);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndEditoryBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndPrekladaceBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndEditoryBar);
DockControlBar(&m_wndPrekladaceBar);
UpdateWindow();
CRect rc;
GetClientRect(&rc);
ClientToScreen(&rc);
DockControlBar(&m_wndEditoryBar,(UINT)0,CRect(rc.left+180,rc.top+5,rc.left+180,rc.top+5));
DockControlBar(&m_wndPrekladaceBar,(UINT)0,CRect(rc.left+350,rc.top+5,rc.left+350,rc.top+5));
_adv=0;
CString untitled;
untitled.LoadString(IDS_UNTITLED);
SetTitle(untitled);
SetClassLong(*this,GCL_HICON,(LONG)(theApp.LoadIcon(IDR_MAINFRAME)));
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnSetFocus(CWnd* pOldWnd)
{
// forward focus to the view window
m_wndView.SetFocus();
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// let the view have first crack at the command
if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// otherwise, do default handling
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
if (_adv==0)
{
for (int i=0,cnt=pPopupMenu->GetMenuItemCount();i<cnt;i++)
{
int id=pPopupMenu->GetMenuItemID(i);
if (id!=ID_FILE_NOVDOBRODRUST && id!=ID_FILE_NATIDOBRODRUSTV && id!=ID_APP_EXIT &&
id!=ID_VIEW_TOOLBAR && id!=ID_VIEW_STATUS_BAR && id!=ID_APP_ABOUT && id!=ID_VIEW_EDITORY)
pPopupMenu->EnableMenuItem(i,MF_GRAYED|MF_BYPOSITION);
}
}
else
CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
}
#include "DlgNoveDobr.h"
static str_add_wildcard(TSTR_LIST *lst, const char *mask)
{
CFileFind fnd;
BOOL nxt=fnd.FindFile(mask);
if (nxt==FALSE)
{
CString msg;
AfxFormatString1(msg,IDS_NEMOHUNAJITNICOD,mask);
AfxMessageBox(msg,MB_ICONEXCLAMATION);
}
while (nxt)
{
nxt=fnd.FindNextFile();
str_add(lst,fnd.GetFilePath());
}
}
void CMainFrame::OnFileNovdobrodrust()
{
DlgNoveDobr dlg;
int id=dlg.DoModal();
if (id==IDOK)
{
release_list(_adv);
_adv=create_list(10);
CString baseMap=_T("adv\\")+dlg.vJmeno+_T("\\");
add_field_txt(&_adv,_T("CESTA_MAPY"),baseMap);
CString cestaGrafika;
CString cestaDialogy;
CString cestaEnemy;
CString cestaItemy;
CString cestaPozice;
CString cestaZvuky;
CString cestaBasicGr;
switch (dlg.vOrganizace)
{
case 0:
cestaGrafika=baseMap+_T("GRFSTENY\\");
cestaDialogy=baseMap+_T("GRFDIALG\\");
cestaEnemy=baseMap+_T("GRFENEMY\\");
cestaItemy=baseMap+_T("GRFITEMS\\");
cestaPozice=baseMap+_T("SAVEGAME\\");
cestaZvuky=baseMap+_T("SOUNDS\\");
cestaBasicGr=baseMap+_T("GRFBASIC\\");
break;
case 1:
cestaGrafika=baseMap+_T("graphics\\");
cestaDialogy=baseMap+_T("graphics\\dialogs\\");
cestaEnemy=baseMap+_T("graphics\\enemies\\");
cestaItemy=baseMap+_T("graphics\\items\\");
cestaPozice=baseMap+_T("SAVEGAME\\");
cestaZvuky=baseMap+_T("SAMPLES\\");
cestaBasicGr=baseMap+_T("graphics\\basic\\");
break;
case 2:
cestaGrafika=baseMap;
cestaDialogy=baseMap;
cestaEnemy=baseMap;
cestaItemy=baseMap;
cestaPozice=baseMap+_T("SAVEGAME\\");
cestaZvuky=baseMap;
cestaBasicGr=baseMap;
break;
}
add_field_txt(&_adv,_T("CESTA_GRAFIKA"),cestaGrafika);
add_field_txt(&_adv,_T("CESTA_DIALOGY"),cestaDialogy);
add_field_txt(&_adv,_T("CESTA_ENEMY"),cestaEnemy);
add_field_txt(&_adv,_T("CESTA_ITEMY"),cestaItemy);
add_field_txt(&_adv,_T("CESTA_POZICE"),cestaPozice);
add_field_txt(&_adv,_T("CESTA_ZVUKY"),cestaZvuky);
add_field_txt(&_adv,_T("CESTA_BGRAFIKA"),cestaBasicGr);
add_field_txt(&_adv,_T("DEFAULT_MAP"),dlg.vStartMap);
add_field_num(&_adv,_T("CHAR_MIN"),dlg.vMinPostav);
add_field_num(&_adv,_T("CHAR_MAX"),dlg.vMaxPostav);
add_field_num(&_adv,_T("PATCH"),1);
Pathname pth=Pathname::GetExePath();
pth.SetFiletitle(dlg.vJmeno);
pth.SetExtension(_T(".adv"));
save_config(_adv,pth);
_advName=pth;
_advPath=pth.GetDirectoryWithDrive();
SetTitle(pth);
Pathname exePath=Pathname::GetExePath();
pth.CreateFolder(exePath.GetDirectoryWithDrive()+baseMap);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaGrafika);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaDialogy);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaItemy);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaEnemy);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaPozice);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaZvuky);
pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaBasicGr);
CString basePath=pth.GetDirectoryWithDrive();
TSTR_LIST fileList=create_list(10);
str_add_wildcard(&fileList,basePath+_T("maps\\*.dat"));
if (!dlg.vDefinice) str_add_wildcard(&fileList,basePath+_T("AdvManData\\weapons.scr"));
if (!dlg.vDefinice) str_add_wildcard(&fileList,basePath+_T("AdvManData\\items.scr"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\items.pic"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\*.lst"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\postavy.def"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\postavy.tab"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\predmety.tab"));
if (dlg.vKouzla)
{
str_add_wildcard(&fileList,basePath+_T("AdvManData\\kouzla.def"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\kouzla.tab"));
}
if (dlg.vDialogy)
{
str_add_wildcard(&fileList,basePath+_T("AdvManData\\dialogy.def"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\dlgsecrt.def"));
}
if (dlg.vDefinice)
{
str_add_wildcard(&fileList,basePath+_T("AdvManData\\*.scr"));
str_add_wildcard(&fileList,basePath+_T("AdvManData\\*.txt"));
}
if (dlg.vMapy)
{
str_add_wildcard(&fileList,basePath+_T("maps\\*.map"));
}
if (dlg.vDialogyDlg)
{
str_add_wildcard(&fileList,basePath+_T("AdvManData\\*.dlg"));
}
int totalszneed=0;
int i,cnt;
for (i=0,cnt=str_count(fileList);i<cnt;i++)
{
const char *file=fileList[i];
if (file) totalszneed+=_tcslen(file)+1;
}
char *buffer=(char *)alloca((totalszneed+1)*sizeof(*buffer));
char *ptr=buffer;
for (i=0,cnt=str_count(fileList);i<cnt;i++)
{
const char *file=fileList[i];
if (file)
{
strcpy(ptr,file);
ptr=_tcschr(ptr,0)+1;
}
}
*ptr=0;
pth.SetDirectory(exePath.GetDirectoryWithDrive()+baseMap);
CString target;
pth.GetDirectoryWithDriveWLBS(target.GetBuffer(_tcslen(pth.GetDirectoryWithDrive())),_tcslen(pth.GetDirectoryWithDrive()));
target.ReleaseBuffer();
SHFILEOPSTRUCT oper;
memset(&oper,0,sizeof(oper));
oper.hwnd=*this;
oper.wFunc=FO_COPY;
oper.pFrom=buffer;
oper.pTo=target;
oper.fFlags=0;
SHFileOperation(&oper);
release_list(fileList);
_baseMapPath=_advPath+baseMap;
CFileFind fnd;
BOOL f=fnd.FindFile(_baseMapPath+"*.*");
while (f)
{
f=fnd.FindNextFile();
SetFileAttributes(fnd.GetFilePath(),GetFileAttributes(fnd.GetFilePath()) &~FILE_ATTRIBUTE_READONLY);
}
AfxMessageBox(IDS_NOVEDOBRODRUZSTVIDOKONCENO,MB_ICONINFORMATION);
}
}
void CMainFrame::OnFileNatidobrodrustv()
{
CString filter;
filter.LoadString(IDS_ADVFILTER);
CFileDialog fdlg(TRUE,_T(".ADV"),0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,filter);
if (fdlg.DoModal()==IDOK)
{
release_list(_adv);
_adv=read_config(fdlg.GetPathName());
if (_adv==0)
{
AfxMessageBox(IDS_CHYBAPRICTENI);
}
else
{
Pathname pth=fdlg.GetPathName();
SetTitle(pth);
_advPath=pth.GetDirectoryWithDrive();
_baseMapPath=_advPath+get_text_field(_adv,"CESTA_MAPY");
_advName=pth;
}
}
}
void CMainFrame::SetTitle(const _TCHAR *name)
{
Pathname nm=name;
CString title;
title.Format(IDS_MAINFRAMETITLE,nm.GetTitle());
SetWindowText(title);
}
void CMainFrame::OnEditoryKouzlatab()
{
OpenEditor(_baseMapPath+"KOUZLA.TAB");
}
void CMainFrame::OnEditoryPostavytab()
{
OpenEditor(_baseMapPath+"POSTAVY.TAB");
}
void CMainFrame::OnEditoryItemsscr()
{
OpenEditor(_baseMapPath+"ITEMS.SCR");
}
void CMainFrame::OnEditoryItemspic()
{
OpenEditor(_baseMapPath+"ITEMS.PIC");
}
void CMainFrame::OnEditoryWeaponsscr()
{
OpenEditor(_baseMapPath+"WEAPONS.SCR");
}
static BOOL CALLBACK BroadcastMsgCallback(HWND wnd, LPARAM lParam)
{
MSG *pMsg=(MSG *)lParam;
LRESULT res=::SendMessage(wnd,pMsg->message,pMsg->wParam,pMsg->lParam);
pMsg->time=res;
return res==0;
}
LRESULT CMainFrame::BroadcastMessage(UINT msg, WPARAM wParam, LPARAM lParam)
{
MSG Msg;
Msg.message=msg;
Msg.wParam=wParam;
Msg.lParam=lParam;
Msg.time=0;
EnumThreadWindows(GetCurrentThreadId(),BroadcastMsgCallback,(LPARAM)&Msg);
return Msg.time;
}
void CMainFrame::SaveAll()
{
BroadcastMessage(MSG_FORCESAVE,0,0);
}
void CMainFrame::OpenEditor(const char *name)
{
if (BroadcastMessage(MSG_FINDANDPOPUP,0,(LPARAM)name)==0)
{
EditSkeldalFile(name);
}
}
void CMainFrame::OnDestroy()
{
SaveBarState("MainFrame");
CFrameWnd::OnDestroy();
BroadcastMessage(MSG_CLOSEEDITOR,0,0);
release_list(_adv);
_adv=0;
}
void CMainFrame::StartApp(const char *appname, CString cmdline, bool wait, const char *folder)
{
SaveAll();
STARTUPINFO nfo;
memset(&nfo,0,sizeof(nfo));
nfo.cb=sizeof(nfo);
HANDLE pipe;
if (wait)
{
HANDLE output;
CreatePipe(&pipe,&output,0,0);
DuplicateHandle(GetCurrentProcess(),output,GetCurrentProcess(),&output,0,TRUE,DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE);
nfo.hStdOutput=output;
nfo.hStdError=output;
nfo.dwFlags|=STARTF_USESTDHANDLES;
m_wndView.SetWindowText("");
}
Pathname app=appname;
cmdline=_T("\"")+CString(appname)+_T("\" ")+cmdline;
CString startdir;
PROCESS_INFORMATION pi;
if (folder==0)
startdir=app.GetDirectoryWithDrive();
else
startdir=folder;
if (startdir[startdir.GetLength()-1]=='\\') startdir.Delete(startdir.GetLength()-1);
BOOL res=CreateProcess(appname,cmdline.LockBuffer(),0,0,TRUE,NORMAL_PRIORITY_CLASS|DETACHED_PROCESS,0,startdir,&nfo,&pi);
cmdline.UnlockBuffer();
if (res==FALSE)
{
CString ss;
AfxFormatString1(ss,IDS_CANNOTEXECUTE,cmdline);
AfxMessageBox(ss,MB_ICONSTOP);
}
else
{
CloseHandle(pi.hThread);
if (wait)
{
int rep=10;
bool end;
do
{
DWORD datalen;
PeekNamedPipe(pipe,0,0,0,&datalen,0);
while (datalen)
{
DWORD readed=0;
char buff[256];
if (ReadFile(pipe,&buff,255,&readed,0)==FALSE) break;
if (readed==0) break;
int cnt=m_wndView.GetWindowTextLength();
if (cnt>20000)
{
m_wndView.SetSel(0,10000);
m_wndView.ReplaceSel("");
cnt=m_wndView.GetWindowTextLength();
}
buff[readed]=0;
kamenik2windows(buff,readed,buff);
m_wndView.SetSel(cnt,cnt);
m_wndView.ReplaceSel(buff);
PeekNamedPipe(pipe,0,0,0,&datalen,0);
rep=10;
}
UpdateWindow();
end=WaitForSingleObject(pi.hProcess,200)==WAIT_TIMEOUT;
rep--;
}
while (rep>0 || end);
}
CloseHandle(pi.hProcess);
}
if (wait)
{
CloseHandle(pipe);
CloseHandle(nfo.hStdOutput);
}
SetForegroundWindow();
}
void CMainFrame::OnPekladaePelokouzla()
{
CString cmdline=_T("\"")+_baseMapPath+_T("KOUZLA.TAB")+_T("\"");
Pathname apppath=Pathname::GetExePath();
CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\CSPELLS.EXE"));
StartApp(appname,cmdline,true,_baseMapPath);
}
void CMainFrame::OnPekladaePelodialogy()
{
CString cmdline=_T("\"")+_baseMapPath+_T("DIALOGY.DLG")+_T("\"");
Pathname apppath=Pathname::GetExePath();
CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\CDIALOGY.EXE"));
StartApp(appname,cmdline,true,_baseMapPath);
}
void CMainFrame::OnPekladaePelopostavytab()
{
CString cmdline=_T("\"")+_baseMapPath+_T("POSTAVY.TAB\" \"")+_baseMapPath+_T("POSTAVY.DAT")+_T("\"");
Pathname apppath=Pathname::GetExePath();
CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\Lex_Lib.exe"));
StartApp(appname,cmdline,true,_baseMapPath);
}
void CMainFrame::OnNstrojeMapedit()
{
Pathname apppath=Pathname::GetExePath();
apppath.SetFilename(_T("MapEdit.exe"));
StartApp(apppath,CString(_T("\""))+_advName+_T("\""),false);
}
void CMainFrame::OnNstrojeTestujdobrodrustv()
{
Pathname apppath=Pathname::GetExePath();
apppath.SetFilename(_T("Skeldal.exe"));
StartApp(apppath,CString(_T("\""))+_advName+_T("\""),false);
}
void CMainFrame::OnNstrojeTvrcepodlah()
{
Pathname apppath=Pathname::GetExePath();
apppath.SetFilename(_T("AdvManData\\Podlahar.exe"));
StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_GRAFIKA"));
}
void CMainFrame::OnNstrojeTvrcepaletpronestvry()
{
Pathname apppath=Pathname::GetExePath();
apppath.SetFilename(_T("AdvManData\\ColEdit.exe"));
StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_ENEMY"));
}
void CMainFrame::OnNstrojeTvrceikonpropedmty()
{
Pathname apppath=Pathname::GetExePath();
apppath.SetFilename(_T("AdvManData\\ItemIcons.exe"));
StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_ITEMY"));
}
void CMainFrame::OnEditorySouboradv()
{
AfxMessageBox(IDS_EDITADVWARN,MB_ICONEXCLAMATION);
OpenEditor(_advName);
}
void CMainFrame::OnFileZnovunast()
{
release_list(_adv);
_adv=read_config(_advName);
_baseMapPath=_advPath+get_text_field(_adv,"CESTA_MAPY");
}
void CMainFrame::OnUpdateFileZnovunast(CCmdUI* pCmdUI)
{
pCmdUI->Enable(_adv!=0);
}
void CMainFrame::OnEditoryDialogy()
{
DlgDialogy dlg;
dlg._dlgpath.SetDirectory(_baseMapPath);
dlg._dlgpath.SetFilename(_T("Dialogy.dlg"));
dlg.DoModal();
}
void CMainFrame::OnUpdateEditory(CCmdUI *pCmdUI)
{
pCmdUI->Enable(_adv!=0);
}

95
AdvMan/MainFrm.h Normal file
View file

@ -0,0 +1,95 @@
// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MAINFRM_H__0420AD88_2B58_4379_BD0D_069A821C039D__INCLUDED_)
#define AFX_MAINFRM_H__0420AD88_2B58_4379_BD0D_069A821C039D__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ChildView.h"
class CMainFrame : public CFrameWnd
{
public:
CMainFrame();
protected:
DECLARE_DYNAMIC(CMainFrame)
// Attributes
public:
TSTR_LIST _adv;
CString _baseMapPath;
CString _advPath;
CString _advName;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
//}}AFX_VIRTUAL
// Implementation
public:
void StartApp(const char *appname, CString cmdline, bool wait, const char *folder=0);
void OpenEditor(const char *name);
void SaveAll();
static LRESULT BroadcastMessage(UINT msg, WPARAM wParam, LPARAM lParam);
void SetTitle(const _TCHAR *name);
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CToolBar m_wndEditoryBar;
CToolBar m_wndPrekladaceBar;
CEdit m_wndView;
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSetFocus(CWnd *pOldWnd);
afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
afx_msg void OnFileNovdobrodrust();
afx_msg void OnFileNatidobrodrustv();
afx_msg void OnEditoryKouzlatab();
afx_msg void OnEditoryPostavytab();
afx_msg void OnEditoryItemsscr();
afx_msg void OnEditoryItemspic();
afx_msg void OnEditoryWeaponsscr();
afx_msg void OnDestroy();
afx_msg void OnPekladaePelokouzla();
afx_msg void OnPekladaePelodialogy();
afx_msg void OnPekladaePelopostavytab();
afx_msg void OnNstrojeMapedit();
afx_msg void OnNstrojeTestujdobrodrustv();
afx_msg void OnNstrojeTvrcepodlah();
afx_msg void OnNstrojeTvrcepaletpronestvry();
afx_msg void OnNstrojeTvrceikonpropedmty();
afx_msg void OnEditorySouboradv();
afx_msg void OnFileZnovunast();
afx_msg void OnUpdateFileZnovunast(CCmdUI* pCmdUI);
afx_msg void OnEditoryDialogy();
afx_msg void OnUpdateEditory(CCmdUI *pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAINFRM_H__0420AD88_2B58_4379_BD0D_069A821C039D__INCLUDED_)

621
AdvMan/Pathname.cpp Normal file
View file

@ -0,0 +1,621 @@
// Pathname.cpp: implementation of the Pathname class.
//
//////////////////////////////////////////////////////////////////////
#include "Pathname.h"
#include <malloc.h>
#include <windows.h>
#include <stdio.h>
#include <shlobj.h>
#include <io.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#pragma comment(lib,"User32")
#pragma comment(lib,"shell32")
Pathname::Pathname(const char *name)
{
_fullpath=NULL;
_path=_filetitle=_extension=_end="";
if (name==NULL) SetPathName("*.*");
else SetPathName(name);
}
Pathname::Pathname(PathNameNullEnum null)
{
_fullpath=NULL;
_path=_filetitle=_extension=_end="";
}
Pathname::Pathname(const char *relpath, const Pathname &abspath)
{
_path=_filetitle=_extension=_end="";
_fullpath=NULL;
char *part;
char *pth=strcpy((char *)alloca(sizeof(*relpath)+strlen(relpath)+1),relpath);
part=strrchr(pth,'\\');
if (part) part++;else part=NULL;
if (part)
{
SetFilename(part);
*part=0;
SetDirectory(pth);
}
else
SetFilename(pth);
if (RelativeToFull(abspath)==false) SetNull();
}
Pathname::~Pathname()
{
delete [] _fullpath;
}
const char *Pathname::GetNameFromPath(const char *path)
{
char *c=strrchr(path,'\\');
if (c!=NULL) c++;else return path;
return c;
}
const char *Pathname::GetExtensionFromPath(const char *path)
{
const char *fname=GetNameFromPath(path);
char *c=strrchr(fname,'.');
if (c==NULL) c=strrchr(path,0);
return c;
}
void Pathname::RebuildData(const char *path, const char *filetitle, const char *extension, int pathlen, int titlelen, int extlen)
{
int totalsize=(pathlen+titlelen+extlen)*2+10;
char *olddata=_fullpath;
_fullpath=new char[totalsize];
_path=_fullpath+pathlen+titlelen+extlen+1;
memcpy(_path,path,pathlen+1);
_filetitle=_path+pathlen+1;
memcpy(_filetitle,filetitle,titlelen+1);
_extension=_filetitle+titlelen+1;
memcpy(_extension,extension,extlen+1);
_end=_extension+extlen+1;
RebuildPath();
delete [] olddata;
}
void Pathname::RebuildPath()
{
sprintf(_fullpath,"%s%s%s",_path,_filetitle,_extension);
}
void Pathname::SetDrive(const char dr)
{
if (HasDrive())
{
if (dr==0)
{
strcpy(_path,_path+2);
strcpy(_fullpath,_fullpath+2);
}
else
{
_path[0]=dr;
_fullpath[0]=dr;
}
}
else if (dr!=0)
{
int np=IsNetworkPath();
if (np)
{
_path[0]=dr;
_path[1]=':';
strcpy(_path+2,_path+np);
RebuildPath();
}
else
{
char *c=(char *)alloca((strlen(_path)+4)*sizeof(*c));
sprintf(c,"%c:%s",dr,_path);
SetDirectory(c);
}
}
}
void Pathname::SetDirectory(const char *dir)
{
bool copydrv; //directory doesn't contain drive, need copy from original
bool addslash; //directory doesn't ending by backslash, need add it
int len=strlen(dir);
copydrv=HasDrive() && !HasDrive(dir); //copy original drive, if exists and directory doesn't contaion drive
if (strncmp(dir,"\\\\",2)==0) copydrv=false; //network path, don't copy drive
addslash=len && dir[len-1]!='\\'; //add slash
if (addslash || copydrv)
{
char *c=(char *)alloca((len+4)*sizeof(dir[0])); //allocate some space for string
if (addslash && copydrv)
sprintf(c,"%c%c%s\\",_path[0],_path[1],dir); //add drive and add slash
else if (addslash)
sprintf(c,"%s\\",dir); //add slash only
else
sprintf(c,"%c%c%s",_path[0],_path[1],dir); //add drive only
dir=c; //this is new path for now
len=strlen(dir);
}
if (len<_filetitle-_path) //there is space for store path
{strcpy(_path,dir); RebuildPath();} //store it and rebuild result
else
RebuildData(dir,_filetitle,_extension,len,strlen(_filetitle),strlen(_extension));
//rebuild internal data complettly
}
void Pathname::SetFilename(const char *filename)
{
char *dot=strrchr(filename,'.');
if (dot==NULL)
{
SetFiletitle(filename);
SetExtension("");
return;
}
int tllen=dot-filename;
int exlen=strlen(dot);
char *c=(char *)alloca((tllen+1)*sizeof(*c));
memcpy(c,filename,tllen);
c[tllen]=0;
if (exlen+tllen+1<_end-_filetitle)
{
memcpy(_filetitle,c,tllen+1);
_extension=_filetitle+tllen+1;
memcpy(_extension,dot,exlen+1);
RebuildPath();
}
else
RebuildData(_path,c,dot,strlen(_path),tllen,exlen);
}
void Pathname::SetExtension(const char *ext)
{
int len=strlen(ext);
if (ext[0] && ext[0]!='.')
{
char *s=(char *)alloca((len+2)*sizeof(*s));
sprintf(s,".%s",ext);
ext=s;
len++;
}
if (len<_end-_extension)
{
memcpy(_extension,ext,len+1);
RebuildPath();
}
else
{
RebuildData(_path,_filetitle,ext,strlen(_path),strlen(_filetitle),len);
}
}
void Pathname::SetFiletitle(const char *title)
{
int len=strlen(title);
if (len<_extension-_filetitle)
{
memcpy(_filetitle,title,len+1);
RebuildPath();
}
else
{
RebuildData(_path,title,_extension,strlen(_path),len,strlen(_extension));
}
}
void Pathname::SetPathName(const char *pathname)
{
if (pathname==NULL || pathname[0]==0)
{
SetNull();
return;
}
char *part;
DWORD needsz=GetFullPathName(pathname,0,NULL,&part);
char *fpth=(char *)alloca(needsz*sizeof(*fpth));
GetFullPathName(pathname,needsz,fpth,&part);
part=strrchr(fpth,'\\');
if (part) part++;else part=NULL;
if (part)
{
SetFilename(part);
*part=0;
}
else
SetFilename("");
SetDirectory(fpth);
}
Pathname& Pathname::operator=(const Pathname& other)
{
if (other.IsNull()) SetNull();
else RebuildData(other._path,other._filetitle,other._extension,strlen(other._path),strlen(other._filetitle),strlen(other._extension));
return *this;
}
Pathname::Pathname(const Pathname &other)
{
_fullpath=NULL;
if (other.IsNull()) SetNull();
else RebuildData(other._path,other._filetitle,other._extension,strlen(other._path),strlen(other._filetitle),strlen(other._extension));
}
bool Pathname::FullToRelative(const Pathname &relativeto)
{
if (relativeto.IsNull() || IsNull()) return false;
bool h1=HasDrive();
bool h2=relativeto.HasDrive();
if (h1!=h2) return false; //rozdilny zpusob adresace - nelze vytvorit relatvni cestu
if (h1==true && h2==true && toupper(GetDrive())!=toupper(relativeto.GetDrive()))
return false; //ruzne disky, nelze vytvorit relativni cestu
if (strncmp(_path,"\\\\",2)==0) //sitova cesta
{
int slsh=0; //citac lomitek
const char *a=_path;
const char *b=relativeto._path;
while (toupper(*a)==toupper(*b) && *a && slsh<3) //zacatek sitove cesty musi byt stejny
{
if (*a=='\\') slsh++;
a++;b++;
}
if (slsh!=3) return false; //pokud neni stejny, nelze vytvorit relativni cestu
}
int sublevel=0;
const char *ps1=_path;
const char *ps2=relativeto._path;
if (h1)
{ps1+=2;ps2+=2;}
const char *sls=ps2;
while (toupper(*ps1)==toupper(*ps2) && *ps1)
{
if (*ps2=='\\') sls=ps2+1;
ps1++;ps2++;
}
ps1-=ps2-sls;
if (sls)
{
while (sls=strchr(sls,'\\'))
{
sls++;
sublevel++;
}
}
char *buff=(char *)alloca((sublevel*3+strlen(ps1)+1)*sizeof(*buff));
char *pos=buff;
for (int i=0;i<sublevel;i++)
{strcpy(pos,"..\\");pos+=3;}
strcpy(pos,ps1);
SetDrive(0);
SetDirectory(buff);
return true;
}
bool Pathname::RelativeToFull(const Pathname &ref)
{
if (ref.IsNull() || IsNull()) return false;
const char *beg;
if (HasDrive())
if (toupper(GetDrive())!=toupper(ref.GetDrive())) return false;
else beg=_path+2;
else beg=_path;
const char *end=strchr(ref._path,0);
if (beg[0]=='\\')
{
int np;
if (ref.HasDrive()) end=ref._path+2;
else if (np=ref.IsNetworkPath()) end=ref._path+np;
else end=ref._path;
}
else while (strncmp(beg,"..\\",3)==0 || strncmp(beg,".\\",2)==0)
{
if (beg[1]=='.')
{
if (end>ref._path)
{
end--;
while (end>ref._path && end[-1]!='\\') end--;
}
beg+=3;
}
else
beg+=2;
}
int partln=end-ref._path;
char *buff=(char *)alloca((partln+strlen(beg)+1)*sizeof(*buff));
memcpy(buff,ref._path,partln);
strcpy(buff+partln,beg);
SetDrive(0);
SetDirectory(buff);
return true;
}
int Pathname::IsNetworkPath() const
{
if (strncmp(_path,"\\\\",2)==0) //sitova cesta
{
const char *p=_path+2;
char *c=strchr(p,'\\');
if (c) return c-_path;
}
return 0;
}
void Pathname::SetServerName(const char *server)
{
if (HasDrive()) SetDrive(0);
else
{
int np=IsNetworkPath();
if (np) strcpy(_path,_path+np); //str
}
char *buff=(char *)alloca((strlen(server)+strlen(_path)+5)*sizeof(*buff));
if (_path[0]!='\\')
sprintf(buff,"\\\\%s\\%s",server,_path);
else
sprintf(buff,"\\\\%s%s",server,_path);
SetDirectory(buff);
}
void Pathname::SetNull()
{
delete [] _fullpath;
_fullpath=NULL;
_path=_filetitle=_extension=_end="";
}
bool Pathname::GetPartFromPath(const char *path, int partnum, char *buff, int bufsize, int mode)
{
const char *scan=path;
while (*scan=='\\') scan++;
while (partnum && *scan)
{
while (*scan!='\\' && *scan) scan++;
while (*scan=='\\') scan++;
partnum--;
}
if (*scan==0)
{
buff[0]=0;
return false;
}
int pt=0;
if (mode==-1)
{
pt=scan-path;
if (pt>bufsize)
{
buff[0]=0;
return true;
}
else
memcpy(buff,path,pt);
}
bool nlast=false;
while (*scan && (mode==1 || !nlast) && pt<bufsize)
{
buff[pt]=*scan;
pt++;
scan++;
if (*scan=='\\') nlast=true;
}
if (pt==bufsize)
{
buff[0]=0;
return true;
}
buff[pt]=0;
return nlast;
}
bool Pathname::GetDirectoryWithDriveWLBS(char *buff, size_t size) const
{
size_t psize=strlen(GetDirectoryWithDrive());
if (psize>size) return false;
if (psize==0) {buff[0]=0;return true;}
strncpy(buff,GetDirectoryWithDrive(),psize-1);
buff[psize-1]=0;
return true;
}
bool Pathname::IsPathValid() const
{
if (IsNull()) return false;
char *invalidChars="/*?\"<>|";
const char *path=GetFullPath();
if (*path==0) return false;
while (*path)
{
if (strchr(invalidChars,*path)!=NULL) return false;
path++;
}
return true;
}
bool Pathname::SetTempDirectory()
{
char buff[1];
DWORD size=GetTempPath(1,buff);
if (size==0) return false;
size++;
char *p=(char *)alloca(size);
if (GetTempPath(size,p)==0) return false;
SetDirectory(p);
return true;
}
bool Pathname::SetDirectorySpecial(int nSpecCode)
{
char buff[MAX_PATH];
if (SHGetSpecialFolderPath(GetForegroundWindow(),buff,nSpecCode,FALSE)!=NOERROR) return false;
SetDirectory(buff);
return true;
}
bool Pathname::SetTempFile(const char *prefix, unsigned int unique)
{
char tempname[MAX_PATH];
if (GetTempFileName(GetDirectoryWithDrive(),prefix,unique,tempname)==0) return false;
this->SetPathName(tempname);
return true;
}
Pathname Pathname::GetExePath()
{
char buff[MAX_PATH*4];
GetModuleFileName(NULL,buff,sizeof(buff));
return Pathname(buff);
}
const char *Pathname::FullToRelativeProjectRoot(const char *full, const char *projectRoot)
{
const char *a=full,*b=projectRoot;
while (*a && tolower(*a)==tolower(*b)) {a++;b++;};
if (*b) return full;
return a;
}
bool Pathname::CreateFolder(void *security_descriptor)
{
int begpart=-1;
int len=strlen(_fullpath)+1;
char *buff=(char *)alloca(len);
for (int i=1;GetPart(i,buff,len,-1);i++)
{
if (begpart==-1 && _access(buff,0)!=0) begpart=i;
if (begpart!=-1)
{
if (begpart==-1) begpart=i;
BOOL res=CreateDirectory(buff,(LPSECURITY_ATTRIBUTES)security_descriptor);
if (res==FALSE)
{
for (int j=i;i>=begpart;i--)
{
GetPart(i,buff,len,-1);
RemoveDirectory(buff);
}
return false;
}
}
}
return true;
}
bool Pathname::CreateFolder(const char *path, void *security_descriptor)
{
Pathname pth;
pth.SetDirectory(path);
return pth.CreateFolder(security_descriptor);
}
static bool RemoveDirectoryFull(const Pathname &p, int part, char *buff, int bufsize)
{
if (p.GetPart(part+1,buff,bufsize,-1))
if (RemoveDirectoryFull(p,part+1,buff,bufsize)==false) return false;
p.GetPart(part,buff,bufsize, -1);
return RemoveDirectory(buff)!=FALSE;
}
static bool RemoveDirRecursive(const char *dir, const char *mask)
{
if (dir==0 || dir[0]==0) return false;
if (strcmp(dir,"\\")==0) return false;
bool res=true;
Pathname newp;
newp.SetDirectory(dir);
if (mask)
{
WIN32_FIND_DATAA fnd;
HANDLE h;
newp.SetFilename(mask);
h=FindFirstFileA(newp,&fnd);
if (h)
{
do
{
if (!(fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
newp.SetFilename(fnd.cFileName);
if (DeleteFile(newp)==FALSE) res=false;
}
}while (FindNextFileA(h,&fnd));
CloseHandle(h);
}
}
{
WIN32_FIND_DATAA fnd;
HANDLE h;
newp.SetFilename("*.*");
h=FindFirstFileA(newp,&fnd);
if (h)
{
do
{
if ((fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(fnd.cFileName,".")!=0 && strcmp(fnd.cFileName,"..")!=0)
{
newp.SetFilename(fnd.cFileName);
if (RemoveDirRecursive(newp,mask)==false) res=false;
else DeleteFile(newp);
}
}while (FindNextFileA(h,&fnd));
CloseHandle(h);
}
}
return res;
}
bool Pathname::DeleteFolder(int dfFlags)
{
int bufflen=strlen(_fullpath)+1;
char *buff=(char *)alloca(bufflen);
/* if (dfFlags & DFRecycleBin)
{
GetDirectoryWithDriveWLBS(buff,bufflen);
SHFILEOPSTRUCT delinfo;
delinfo.hwnd=NULL;
delinfo.wFunc=FO_DELETE;
delinfo.pFrom=GetFullPath();
delinfo.pTo=NULL;
delinfo.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|((dfFlags & DFRecursive)?0:FOF_NORECURSION)|
((dfFlags & DFShowProgress)?0:FOF_SILENT);
delinfo.fAnyOperationsAborted=0;
delinfo.hNameMappings=0;
delinfo.lpszProgressTitle=0;
}
else*/
{
if (dfFlags & DFRecursive)
{
bool res=RemoveDirRecursive(GetDirectoryWithDrive(),dfFlags & DFFile?GetFilename():0);
if (res==false) return false;
}
if (dfFlags & DFPath)
{
if (GetPart(1,buff,bufflen,-1)==false) return false;
return RemoveDirectoryFull(*this, 1,buff,bufflen);
}
else
{
GetDirectoryWithDriveWLBS(buff,bufflen);
return RemoveDirectory(buff)!=FALSE;
}
}
return false;
}

451
AdvMan/Pathname.h Normal file
View file

@ -0,0 +1,451 @@
// Pathname.h: interface for the Pathname class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_Pathname_H__40F41C23_3AA2_486C_B9E5_33AEE67FB313__INCLUDED_)
#define AFX_Pathname_H__40F41C23_3AA2_486C_B9E5_33AEE67FB313__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <ctype.h>
#include <string.h>
#include <assert.h>
#ifndef ASSERT
#ifdef _DEBUG
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif
#endif
enum PathNameNullEnum {PathNull};
#define PathNameCompare(op) bool operator op (const Pathname &other) const \
{if (IsNull() || other.IsNull()) return false;else return stricmp(_fullpath,other._fullpath) op 0;}\
bool operator op (const char *other) const \
{ASSERT(other[0]!=0);\
if (IsNull() || other==NULL) return false;else return stricmp(_fullpath,other) op 0;}
#ifndef _UNICODE
/** class Pathname simplifying manipulation with pathnames, filenames, general paths, and
also supports convert from absolute path to relative respectively */
class Pathname
{
///object value and data
/**The implementation of Pathname creates only one buffer for all variables. It can
increase speed by effective memory use. Strings are stored one after another separated
by zero byte. Evry time any string changed, implementation recalculate buffer usage, and
decide, whether it should resize buffer or not.
_fullpath also points to string contain full path with filename,
it is dominant value of the class
*/
char *_fullpath;
char *_path; ///<current path with drive
char *_filetitle; ///<file title without extension
char *_extension; ///<file extension
char *_end; ///<end of field. Class must know, where buffer ends
public:
///Construct Pathname class.
/** If name is not provided, current path is used, and as filename, Pathname suppl wildcards
*.* . That is useful, for searching in directory.<br>
If name is provided, Pathname will expand it into full name with drive and folder name.
@param name optional argument to inicialize object
*/
Pathname(const char *name=NULL);
///Construct Pathname class
/** Using this constructor Pathname(PathNull) will create Pathname class with null content is set.
If null content is set, all string-query function returns NULL. IsNull function returns true. This state
is sets until new path is assigned. There is a set of functions invalid called in null state.
*/
Pathname(PathNameNullEnum null);
///Construct Pathname class
/**
@param relpath Relative path or uncomplette path or single filename with extension.
Pathname will expand this pathname into full using absolute path provided by the second
argument.
@param abspath Absolute path used as reference to folder - the origin of relative path
provided in the first argument.
*/
Pathname(const char *relpath, const Pathname &abspath);
///Construct Pathname as copy of another pathname
Pathname(const Pathname &other);
///Destruct Pathname
virtual ~Pathname();
///Function returns the current drive letter.
/** Before usage, ensure, that current pathname contain drive.
In network path drive letter is missing.
In this case, result is undefined. To ensure, use HasDrive function
@return the drive letter of current path.
*/
char GetDrive() const
{
if (IsNull()) return 0;
return _path[0];
}
///Static function determines, if argument contain a drive information.
/**
@param dir directory to inspect
@return true, if directory contain drive.<p>
This function is independed, it don't need any Pathname variable declared.
*/
static bool HasDrive(const char *dir)
{return (isalpha(dir[0]) && dir[1]==':');}
///Function determines, if current pathname contain a drive information
/**
@return true, if current pathname contain a drive information
*/
bool HasDrive() const
{
if (IsNull()) return false;
return HasDrive(_path);
}
///Function returns current folder name
/**
if current folder name contain drive, only folder name is returned (without drive).
In other cases (relative or network drives) returns full path.
@return folder name or full path. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const char *GetDirectory() const
{
if (HasDrive()) return _path+3;
else return _path;
}
const char *GetDirectoryWithDrive() const
{
return _path;
}
///Function returns current filename with extension
/**
@return current filename with extension. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const char *GetFilename() const
{
if (IsNull()) return NULL;
const char *blk=strrchr(_fullpath,'\\');
if (blk) blk=blk+1;else blk=_fullpath;
return blk;
}
///Function returns current extension (with starting dot)
/**
@return current extension. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const char *GetExtension() const
{return _extension;}
///Function returns current filename without extension (without dot)
/**
@return current filename without extension (without dot). Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const char *GetTitle() const
{return _filetitle;}
///Function changes current drive.
/**If object contain pathname with drive, then current drive is changed and function returns.
If object contain network path, then computer name is changed to the drive name.
If object contain relative path, then whole path is replaced by path on root on drive.
@param dr new drive letter. This parameter can be set to zero. It means, that current
driver is deleted, and path is converted to relative path from root. Note: Zero c
cannot be used with network paths and relative paths, and finnaly has no effect to the object
*/
void SetDrive(const char dr);
///Sets new directory for object
/** if object contain a drive letter and argument dir doesn't, then current drive is remain
and only directory part is replaced. If current path is network path or relative path,
then whole path is replaced by new one.
If argument dir contain drive letter, then whole path is replaced too.
@param dir contain new pathname. Backslash should be the last character in string
*/
void SetDirectory(const char *dir);
///Sets new filename for object.
/**
If filename contain dot, function assumes, that filename is provided with extension.
Otherwise, current extension remains untouched.
@param filename new filename for object
*/
void SetFilename(const char *filename);
///Sets new extension for object.
/**
If ext doesn't starting with dot, function adds it.
@param ext new extension for object
*/
void SetExtension(const char *ext);
///Sets new file title
/** Function changes file title, extension remains untouched.
if title contains extension (dot inside its name), this extension doesn't change
current extension. For example, if current extension is ".cpp" and filetitle contain
"source.h", then result is "source.h.cpp"
@param title a new title for object.
*/
void SetFiletitle(const char *title);
///Function returns full pathname.
/**
@return current pathname. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const char *GetFullPath() const
{return _fullpath;}
///Sets pathname
/** Function has same effect as constructor. But it can be used
anytime during object lifetime. It simply replaces current pathname with newer. Pathname
in argument is expanded to full pathname, current directory is used as reference.
@param pathname new pathname
*/
void SetPathName(const char *pathname);
Pathname& operator=(const char *other)
{SetPathName(other);return *this;}
Pathname& operator=(const Pathname& other);
///converts object to string
operator const char *() const
{return GetFullPath();}
///Static function to help getting filename from pathname
/** Function finds last backslash / and return pointer to first character after it.
Pointer stays valid until original path is destroyed or until original path is changed
@param path pathname to inspect as string
@return pointer to filename
*/
static const char *GetNameFromPath(const char *path);
///Static function to help getting extension from pathname
/** Function finds last dot '.' in filename return pointer to it (extension with dot).
Pointer stays valid until original path is destroyed or until original path is changed
@param path pathname to inspect as string
@return pointer to extension
*/
static const char *GetExtensionFromPath(const char *path);
///Function sets server name for network path
/** If current path is network path, then changes server name to newer. Otherwise
it remove drive letter, and insert server name before remain path
@param server server name without slashes
*/
void SetServerName(const char *server);
///Function inspects current path and returns, whether contain server name
/**@return zero, if current path is not valid network path. Nonzero if path contain
server name. Then value returned count characters containing server name with precedent
slashes.
*/
int IsNetworkPath() const;
///Function converts current relative path into absolute path
/**
If current path is not relative, function do nothing.
@param ref reference to path, against which path is relative.
@return true if path has been converted, or false, if conversion is impossible
*/
bool RelativeToFull(const Pathname &ref);
///Function converts current absolute path into relative path
/**
If current path is not relative, function do nothing. Both paths must be on the same
drive or network computer.
@param ref reference to path, against which path should be relative.
@return true if path has been converted, or false, if conversion is impossible
*/
bool FullToRelative(const Pathname &relativeto);
Pathname& operator+=(const char *relativePath)
{*this=Pathname(relativePath,*this);return *this;}
Pathname operator+(const char *relativePath)
{Pathname out(relativePath,*this);return out;}
bool IsNull() const {return _fullpath==NULL;}
void SetNull();
PathNameCompare(<)
PathNameCompare(>)
PathNameCompare(==)
PathNameCompare(>=)
PathNameCompare(<=)
PathNameCompare(!=)
///Function gets part of pathname
/**
@param path subject of examine
@param partnum zero-base index of part of pathname. Index 0 mostly contain drive or server, in case of
relative path, there is the name of the first folder or dots.
@param buff buffer for store result
@param bufsize count characters in buffer;
@param mode mode=0, gets only name of part.
mode=1, get current part and remain parts of path.
mode=-1, gets all parts till current
@return Function returns true, if it was succesful, and it was not last part. Function returns
false, if it was succesful, and it was last part. Function returns false and sets buffer empty,
if an error occured. Function returns true and sets buffer empty, if buffer is too small to hold data
*/
static bool GetPartFromPath(const char *path, int partnum, char *buff, int bufsize, int mode=0);
///Function gets part of object
/**
@param partnum zero-base index of part of pathname. Index 0 mostly contain drive or server, in case of
relative path, there is the name of the first folder or dots.
@param buff buffer for store result
@param bufsize count characters in buffer;
@param mode mode=0, gets only name of part.
mode=1, get current part and remain parts of path.
mode=-1, gets all parts till current
@return Function returns true, if it was succesful, and it was not last part. Function returns
false, if it was succesful, and it was last part. Function returns false and sets buffer empty,
if an error occured. Function returns true and sets buffer empty, if buffer is too small to hold data
*/
bool GetPart(int partnum, char *buff, int bufsize,int mode=0) const
{
return GetPartFromPath(this->_fullpath,partnum,buff,bufsize,mode);
}
/// Get Directory With Drive Without Last Back Slash
/** Retrieves into buffer directory with drive and removes last backslash
@param buff buffer that retrieves path
@param size size of buffer
@return true, if success, failed if buffer is too small*/
bool GetDirectoryWithDriveWLBS(char *buff, size_t size) const;
/// function checks, if path is valid and returns true, if does.
bool IsPathValid() const;
/// Sets special directory.
/**
@param bSpecCode this value may be operation-system
depend. Windows implementation using CSIDL_XXXX constants, which is described in SHGetSpecialFolderLocation function
description
@return true, if function were successful
*/
bool SetDirectorySpecial(int nSpecCode);
///Sets temporaly directory.
bool SetTempDirectory();
///Guess temporaly file name
/**
@param prefix prefix string for name
@param unique if unique is non-zero, it is used for new temporaly file. If unique is zero, function guess own unique
value.
@return true if function were successful
*/
bool SetTempFile(const char *prefix="tmp", unsigned int unique=NULL);
///Returns path of current executable.
/**It useful, when accessing folder, from when current module has been executed */
static Pathname GetExePath();
///Solves most used conversion from fullpath to path relative to project root
/**
@param full full pathname with drive
@param projectRoot project root path
@return function returns pointer to full path, where starts relative part. If
fullpath doesn't contain project root path, it returns pointer to full.
@example FullToProjectRoot("x:\\project\\data\\example.txt","x:\\project"); //result is "data\\example.txt"
*/
static const char *FullToRelativeProjectRoot(const char *full, const char *projectRoot);
///Creates folder from path
static bool CreateFolder(const char *path, void *security_descriptor=0);
///Creates all folders from path stored in object
/**
Function creates path stored in object. Function creates whole path, when it doesn't
exists.
@param security_descriptor pointer for additional information about security on new folder
if this parameter is NULL, default descriptor is used. This parameter is platform
depended.
@return if path has been created, returns true. In case of error, returns false
and no changes are made on disk (Function rollbacks any changes)
*/
bool CreateFolder(void *security_descriptor=0);
enum DeleteFolderFlags {
DFSimple=0, //only deletes latest folder
DFPath=1, //deletes whole path, if there are no files
DFFile=2, //deletes file specified in object. You can use wildcards
DFRecursive=4, //also deletes all folders inside the path
/* DFRecycleBin=8, //move all deleted files or folders into recycle bin
DFShowProgress=16, //enables progress bar during deleting*/
};
///Deletes folder stored in object
/**
@param dfFlags combination of flags.
@return function returns true, when no error occured. Function return false,
when error occured.
*/
bool DeleteFolder(int dfFlags);
protected:
///Function rebuild buffer with new values
/** This protected function recalculates space for buffer, allocated it, and rebuild its
content with data supplied by arguments. Function doesn't assumes, that all strings are
terminated by zero by default. "pathlen, titlelen and extlen" must contain correct values.
Terminating zero is not included, but function excepting it.
Valid using is: RebuildData(a,b,c,strlen(a),strlen(b),strlen(c));
All pointers returned by Get functions can be used and stays valid, until this function returns.
*/
void RebuildData(const char *path, const char *filetitle, const char *extension, int pathlen, int titlelen, int extlen);
///Function only rebuild _fullpath string.
/** It doesn't check space for string! This function is used, when length of path is excepted
the same or smaller, then current.
*/
void RebuildPath();
};
#else
#error unicode version of Pathname is not currently supported
#endif
#undef PathNameCompare
#endif // !defined(AFX_Pathname_H__40F41C23_3AA2_486C_B9E5_33AEE67FB313__INCLUDED_)

8
AdvMan/StdAfx.cpp Normal file
View file

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// AdvMan.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

33
AdvMan/StdAfx.h Normal file
View file

@ -0,0 +1,33 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__978B5377_B3F7_4A88_A4CA_02390EC070E2__INCLUDED_)
#define AFX_STDAFX_H__978B5377_B3F7_4A88_A4CA_02390EC070E2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
extern "C"
{
#include <strlite.h>
#include <inicfg.h>
}
#include "Pathname.h"
#include <malloc.h>
#include "..\mapedit\editor.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__978B5377_B3F7_4A88_A4CA_02390EC070E2__INCLUDED_)

0
AdvMan/bgraph2dx.h Normal file
View file

0
AdvMan/debug.h Normal file
View file

BIN
AdvMan/idc_note.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

4
AdvMan/mem.h Normal file
View file

@ -0,0 +1,4 @@
__inline void *getmem(long sz)
{
return malloc(sz);
}

BIN
AdvMan/res/AdvMan.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

13
AdvMan/res/AdvMan.rc2 Normal file
View file

@ -0,0 +1,13 @@
//
// ADVMAN.RC2 - resources Microsoft Visual C++ does not edit directly
//
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...
/////////////////////////////////////////////////////////////////////////////

BIN
AdvMan/res/Toolbar.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

BIN
AdvMan/res/editory.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

BIN
AdvMan/res/prekladace.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

88
AdvMan/resource.h Normal file
View file

@ -0,0 +1,88 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by AdvMan.rc
//
#define IDC_ADD 4
#define IDC_DELETE 5
#define IDC_RESCAN 6
#define IDD_ABOUTBOX 101
#define IDD_TEXTEDITOR 105
#define IDR_EDITORMENU 107
#define IDI_MAINICON 117
#define IDI_NOTEPADICON 118
#define IDR_MAINFRAME 128
#define IDR_ADVMANTYPE 129
#define IDS_NOVEDOBRODRUZSTVIDOKONCENO 129
#define IDD_NOVEDOBR 130
#define IDS_ADVFILTER 130
#define IDS_CHYBAPRICTENI 131
#define IDS_MAINFRAMETITLE 132
#define IDS_UNTITLED 133
#define IDS_CANNOTEXECUTE 134
#define IDD_DIALOGY 134
#define IDS_NEMOHUNAJITNICOD 135
#define IDD_NOVYDIALOG 135
#define IDS_EDITADVWARN 136
#define IDR_TOOLEDITORY 136
#define IDS_DLGNAME 137
#define IDS_DLGDESC 138
#define IDR_PREKLADACE 138
#define IDS_DLGID 139
#define IDS_UNABLETOSAVEDIALOGYDLG 140
#define IDS_NODESC 141
#define IDC_JMENO 1000
#define IDC_EDIT 1000
#define IDC_ORGANIZACE 1001
#define IDC_RADIO2 1002
#define IDC_RADIO3 1003
#define IDC_KOUZLA 1004
#define IDC_DIALOGY 1005
#define IDC_DEFINICE 1006
#define IDC_MAPY 1007
#define IDC_MAPY2 1008
#define IDC_ORIGDLGS 1008
#define IDC_STARTMAP 1009
#define IDC_MINPOSTAV 1010
#define IDC_MAXPOSTAV 1011
#define IDC_DLGLIST 1012
#define IDC_POPIS 1013
#define IDC_CISLO 1016
#define ID_FILE_NOVDOBRODRUST 32771
#define ID_FILE_NATIDOBRODRUSTV 32773
#define ID_EDITORY_KOUZLATAB 32774
#define ID_EDITORY_POSTAVYTAB 32775
#define ID_EDITORY_DIALOGY 32776
#define ID_EDITORY_ITEMSSCR 32777
#define ID_EDITORY_ITEMSPIC 32778
#define ID_EDITORY_WEAPONSSCR 32779
#define ID_NSTROJE_TVRCEPODLAH 32780
#define ID_NSTROJE_TVRCEPALETPRONESTVRY 32781
#define ID_NSTROJE_TVRCEIKONPROPEDMTY 32782
#define ID_PEKLADAE_PELOKOUZLA 32783
#define ID_PEKLADAE_PELODIALOGY 32784
#define ID_PEKLADAE_PELOPOSTAVYTAB 32785
#define ID_NSTROJE_EXPORTUJDOBRODRUSTV 32786
#define ID_NSTROJE_TEKADDLSOUBOR 32787
#define ID_NSTROJE_MAPEDIT 32788
#define ID_NSTROJE_TESTUJDOBRODRUSTV 32789
#define ID_EDITORY_SOUBORADV 32790
#define ID_FILE_ZNOVUNAST 32791
#define ID_VIEW_PREKLADACE 32802
#define ID_VIEW_EDITORY 32810
#define ID_PRAVY_UNDO 40001
#define ID_UPRAVY_COPY 40002
#define ID_UPRAVY_VYJMOUT 40003
#define ID_UPRAVY_VLOZIT 40004
#define ID_UPRAVY_VYMAZAT 40005
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 140
#define _APS_NEXT_COMMAND_VALUE 32815
#define _APS_NEXT_CONTROL_VALUE 1018
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

4
AdvMan/skeldal_win.h Normal file
View file

@ -0,0 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

93
DDLReader/DDLFile.cpp Normal file
View file

@ -0,0 +1,93 @@
#include "stdafx.h"
#include ".\ddlfile.h"
DDLFile::DDLFile(void)
{
_hFile=0;
}
DDLFile::~DDLFile(void)
{
if (_hFile!=0) CloseHandle(_hFile);
}
bool DDLFile::OpenDDLFile(WString filename)
{
_hFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS,NULL);
if (_hFile==INVALID_HANDLE_VALUE)
{
_hFile=0;
return false;
}
return true;
}
bool DDLFile::ReadFile(void *data, size_t sz)
{
DWORD readed=0;
if (::ReadFile(_hFile,data,sz,&readed,NULL)==FALSE) return false;
if (readed!=sz) return false;
return true;
}
bool DDLFile::EnumFiles(IDDLFileEnumerator &enmClass)
{
unsigned long firstGroup;
unsigned long groupEndOffset;
unsigned long endGroups;
int i;
int ngroups;
SetFilePointer(_hFile,0,0,FILE_BEGIN);
if (ReadFile(&firstGroup,sizeof(firstGroup))==false) return false;
if (ReadFile(&groupEndOffset,sizeof(firstGroup))==false) return false;
unsigned long *group=(unsigned long *)alloca(groupEndOffset);
group[0]=firstGroup;
group[1]=groupEndOffset;
ngroups=groupEndOffset/8;
if (groupEndOffset!=8 && ReadFile(group+2,groupEndOffset-8)==false) return false;
SetFilePointer(_hFile,12,0,FILE_CURRENT);
if (ReadFile(&endGroups,sizeof(endGroups))==false) return false;
for (i=0;i<ngroups && group[i*2+1]<endGroups;i++);
ngroups=i;
WString fname;
for (i=0;i<ngroups;i++)
{
unsigned long endGroup=(i+1)<ngroups?group[i*2+3]:endGroups;
SetFilePointer(_hFile,group[i*2+1],0,FILE_BEGIN);
unsigned long pos=group[i*2+1];
while (pos<endGroup)
{
char buff[13];
unsigned long offset;
if (ReadFile(buff,12)==false) return false;
if (ReadFile(&offset,4)==false) return false;
buff[12]=0;
fname.SetUTF8(buff);
enmClass.File(fname,group[i*2],offset);
pos+=12+4;
}
}
return true;
}
unsigned long DDLFile::GetFileSize(unsigned long offset)
{
unsigned long sz=0;
SetFilePointer(_hFile,offset,0,FILE_BEGIN);
ReadFile(&sz,4);
return sz;
}
DDLData DDLFile::ExtractFile(unsigned long offset)
{
SetFilePointer(_hFile,offset,0,FILE_BEGIN);
DDLData data;
if (ReadFile(&data.sz,4)==false) return DDLData();
data.data=malloc(data.sz);
if (ReadFile(data.data,data.sz)==false) return DDLData();
return data;
}

45
DDLReader/DDLFile.h Normal file
View file

@ -0,0 +1,45 @@
#pragma once
#include "WString.h"
class IDDLFileEnumerator
{
public:
virtual bool File(WString name, int group, unsigned long offset)=0;
};
struct DDLData
{
void *data;
size_t sz;
DDLData():data(0),sz(0) {}
~DDLData() {free(data);}
DDLData(const DDLData &other):data(other.data),sz(other.sz)
{
DDLData &dother=const_cast<DDLData &>(other);
dother.data=0;dother.sz=0;
}
DDLData& operator =(const DDLData &other)
{
DDLData &dother=const_cast<DDLData &>(other);
data=other.data;sz=other.sz;
dother.data=0;dother.sz=0;
return *this;
}
};
class DDLFile
{
HANDLE _hFile;
bool ReadFile(void *data, size_t sz);
public:
DDLFile(void);
~DDLFile(void);
bool OpenDDLFile(WString filename);
bool EnumFiles(IDDLFileEnumerator &enmClass);
DDLData ExtractFile(unsigned long offset);
unsigned long GetFileSize(unsigned long offset);
};

67
DDLReader/DDLReader.cpp Normal file
View file

@ -0,0 +1,67 @@
// DDLReader.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "DDLReader.h"
#include "DDLReaderDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp
BEGIN_MESSAGE_MAP(CDDLReaderApp, CWinApp)
//{{AFX_MSG_MAP(CDDLReaderApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp construction
CDDLReaderApp::CDDLReaderApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDDLReaderApp object
CDDLReaderApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp initialization
BOOL CDDLReaderApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
CDDLReaderDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

49
DDLReader/DDLReader.h Normal file
View file

@ -0,0 +1,49 @@
// DDLReader.h : main header file for the DDLREADER application
//
#if !defined(AFX_DDLREADER_H__9FE8F7F8_112D_4735_A4BA_5141A991D609__INCLUDED_)
#define AFX_DDLREADER_H__9FE8F7F8_112D_4735_A4BA_5141A991D609__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp:
// See DDLReader.cpp for the implementation of this class
//
class CDDLReaderApp : public CWinApp
{
public:
CDDLReaderApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDDLReaderApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CDDLReaderApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DDLREADER_H__9FE8F7F8_112D_4735_A4BA_5141A991D609__INCLUDED_)

278
DDLReader/DDLReader.rc Normal file
View file

@ -0,0 +1,278 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Czech resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CSY)
#ifdef _WIN32
LANGUAGE LANG_CZECH, SUBLANG_DEFAULT
#pragma code_page(1250)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\DDLReader.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\DDLReader.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_EXPORTING DIALOGEX 0, 0, 186, 82
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE |
WS_CAPTION | WS_SYSMENU
CAPTION "Exporting"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER | 0x1,7,39,
172,14
CTEXT "Exporting",IDC_STATIC,7,7,172,8
CTEXT "Static",IDC_NAME,7,23,172,8
PUSHBUTTON "Stop",IDC_BUTTON1,68,61,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_EXPORTING, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 179
TOPMARGIN, 7
BOTTOMMARGIN, 75
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_ABOUTBOX "&About DDLReader..."
IDS_FILEOPENFAILED "Failed to open DDL"
IDC_HEADGROUP "Group"
IDC_HEADFNAME "Filename"
IDC_HEADSIZE "Size"
IDC_HEADOFFSET "Offset"
IDS_DDLFILTER "DDLFiles|*.ddl|All Files|*.*||"
IDC_GROUP_GRAPHICS "Graphics"
IDC_GROUP_SOUNDS "Sounds"
IDC_GROUP_FONTS "Fonts"
IDC_GROUP_BASIC "Basic graphics"
END
STRINGTABLE
BEGIN
IDC_GROUP_ITEMS "Item graphics"
IDC_GROUP_MONSTERS "Monster graphics"
IDC_GROUP_DIALOGS "Dialog graphics"
IDC_GROUP_UNSPECIFIED "Unspecified"
IDC_GROUP_UNKNOWN "Unknown (%d)"
IDS_UNABLETOCREATEFILE "Unable to create target file: \r\n%1"
IDS_UNABLETOEXTACTDATA "Unable to extract data. General reading error"
END
#endif // Czech resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About DDLReader"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "DDLReader Version 1.0",IDC_STATIC,40,10,119,8,
SS_NOPREFIX
LTEXT "Copyright (C) 2005",IDC_STATIC,40,25,119,8
DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP
END
IDD_DDLREADER_DIALOG DIALOGEX 0, 0, 364, 262
STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_CAPTION |
WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "DDLReader"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL "List2",IDC_FILELIST,"SysListView32",LVS_REPORT |
LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,0,14,363,219
LTEXT "Export to folder:",IDC_POPISEK,0,235,50,8
EDITTEXT IDC_FOLDER,0,248,263,14,ES_AUTOHSCROLL
PUSHBUTTON "Browse",IDC_BROWSE,268,248,34,14
PUSHBUTTON "Export",IDC_EXPORT,306,248,58,14
EDITTEXT IDC_DDLFILE,0,0,313,12,ES_AUTOHSCROLL
PUSHBUTTON "Browse DDL",IDC_DDLBROWSE,314,0,50,12
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "FileDescription", "DDLReader MFC Application"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "DDLReader"
VALUE "LegalCopyright", "Copyright (C) 2005"
VALUE "OriginalFilename", "DDLReader.EXE"
VALUE "ProductName", "DDLReader Application"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
IDD_DDLREADER_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 357
TOPMARGIN, 7
BOTTOMMARGIN, 255
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\DDLReader.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

34
DDLReader/DDLReader.sln Normal file
View file

@ -0,0 +1,34 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DDLReader", "DDLReader.vcproj", "{A5326507-3420-4D03-B9EB-5583790B412B}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SourceCodeControl) = preSolution
SccNumberOfProjects = 2
SccProjectName0 = \u0022$/Skeldal/DDLReader\u0022,\u0020NJEAAAAA
SccLocalPath0 = ..\\..\\..
SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
CanCheckoutShared = false
SccProjectFilePathRelativizedFromConnection0 = Projects\\Skeldal\\DDLReader\\
SolutionUniqueID = {A1A5598F-1F71-475C-8CAA-699B487DC20F}
SccProjectUniqueName1 = DDLReader.vcproj
SccLocalPath1 = ..\\..\\..
CanCheckoutShared = false
SccProjectFilePathRelativizedFromConnection1 = Projects\\Skeldal\\DDLReader\\
EndGlobalSection
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{A5326507-3420-4D03-B9EB-5583790B412B}.Debug.ActiveCfg = Debug|Win32
{A5326507-3420-4D03-B9EB-5583790B412B}.Debug.Build.0 = Debug|Win32
{A5326507-3420-4D03-B9EB-5583790B412B}.Release.ActiveCfg = Release|Win32
{A5326507-3420-4D03-B9EB-5583790B412B}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

291
DDLReader/DDLReader.vcproj Normal file
View file

@ -0,0 +1,291 @@
<?xml version="1.0" encoding="windows-1250"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="DDLReader"
ProjectGUID="{A5326507-3420-4D03-B9EB-5583790B412B}"
SccProjectName="&quot;$/Skeldal/DDLReader&quot;, NJEAAAAA"
SccAuxPath=""
SccLocalPath="..\..\.."
SccProvider="MSSCCI:Microsoft Visual SourceSafe"
Keyword="MFCProj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="2"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="1">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Release/DDLReader.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Release/DDLReader.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
ProgramDatabaseFile=".\Release/DDLReader.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Release/DDLReader.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1029"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="2"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="1">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Debug/DDLReader.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Debug/DDLReader.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/DDLReader.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/DDLReader.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1029"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\DDLFile.cpp">
</File>
<File
RelativePath=".\DDLReader.cpp">
</File>
<File
RelativePath=".\DDLReader.rc">
</File>
<File
RelativePath=".\DDLReaderDlg.cpp">
</File>
<File
RelativePath=".\DlgProgress.cpp">
</File>
<File
RelativePath=".\StdAfx.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WPathname.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WString.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WStringMemory.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WStringProxy.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath=".\DDLFile.h">
</File>
<File
RelativePath=".\DDLReader.h">
</File>
<File
RelativePath=".\DDLReaderDlg.h">
</File>
<File
RelativePath=".\DlgProgress.h">
</File>
<File
RelativePath=".\IWStringEffect.h">
</File>
<File
RelativePath=".\resource.h">
</File>
<File
RelativePath=".\StdAfx.h">
</File>
<File
RelativePath=".\WPathname.h">
</File>
<File
RelativePath=".\WString.h">
</File>
<File
RelativePath=".\WStringMemory.h">
</File>
<File
RelativePath=".\WStringProxy.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File
RelativePath=".\res\DDLReader.ico">
</File>
</Filter>
</Files>
<Globals>
<Global
Name="RESOURCE_FILE"
Value="DDLReader.rc"/>
</Globals>
</VisualStudioProject>

533
DDLReader/DDLReaderDlg.cpp Normal file
View file

@ -0,0 +1,533 @@
// DDLReaderDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DDLReader.h"
#include "DDLReaderDlg.h"
#include ".\ddlreaderdlg.h"
#include "WPathname.h"
#include "DlgProgress.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderDlg dialog
CDDLReaderDlg::CDDLReaderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDDLReaderDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDDLReaderDlg)
vFolder = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CDDLReaderDlg::~CDDLReaderDlg()
{
if (!_lastTemp.IsNull()) DeleteFile(_lastTemp);
}
void CDDLReaderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDDLReaderDlg)
DDX_Control(pDX, IDC_FOLDER, wFolder);
DDX_Control(pDX, IDC_FILELIST, wFileList);
DDX_Control(pDX, IDC_BROWSE, wBrowse);
DDX_Control(pDX, IDC_EXPORT, wExport);
DDX_Text(pDX, IDC_FOLDER, vFolder);
DDX_Control(pDX, IDC_POPISEK, wPopisek);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_DDLFILE, wDDLFile);
DDX_Control(pDX, IDC_DDLBROWSE, wDDLBrowse);
}
BEGIN_MESSAGE_MAP(CDDLReaderDlg, CDialog)
//{{AFX_MSG_MAP(CDDLReaderDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
ON_EN_KILLFOCUS(IDC_DDLFILE, OnEnKillfocusDdlfile)
ON_BN_CLICKED(IDC_DDLBROWSE, OnBnClickedDdlbrowse)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_FILELIST, OnLvnColumnclickFilelist)
ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
ON_BN_CLICKED(IDC_EXPORT, OnBnClickedExport)
ON_NOTIFY(NM_DBLCLK, IDC_FILELIST, OnNMDblclkFilelist)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderDlg message handlers
BOOL CDDLReaderDlg::OnInitDialog()
{
CRect rc;
GetClientRect(&rc);
_dlgSize=rc.Size();
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString header;
header.LoadString(IDC_HEADGROUP);
wFileList.InsertColumn(0,header,LVCFMT_CENTER,100,0);
header.LoadString(IDC_HEADFNAME);
wFileList.InsertColumn(1,header,LVCFMT_LEFT,140,1);
header.LoadString(IDC_HEADSIZE);
wFileList.InsertColumn(2,header,LVCFMT_RIGHT,80,2);
header.LoadString(IDC_HEADOFFSET);
wFileList.InsertColumn(3,header,LVCFMT_RIGHT,80,3);
ListView_SetExtendedListViewStyleEx(wFileList,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDDLReaderDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDDLReaderDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDDLReaderDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void MoveWindowRel(HDWP &hdwp, CWnd &wnd, int xr,int yr, int xs, int ys)
{
CRect rc;
wnd.GetWindowRect(&rc);
wnd.GetParent()->ScreenToClient(&rc);
rc.left+=xr;
rc.top+=yr;
rc.bottom+=yr+ys;
rc.right+=xr+xs;
hdwp=DeferWindowPos(hdwp,wnd,NULL,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,SWP_NOZORDER);
}
void CDDLReaderDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (nType!=SIZE_MINIMIZED)
{
if (wFileList.GetSafeHwnd()!=0)
{
HDWP dwp=BeginDeferWindowPos(10);
int difx=cx-_dlgSize.cx;
int dify=cy-_dlgSize.cy;
MoveWindowRel(dwp,wFileList,0,0,difx,dify);
MoveWindowRel(dwp,wPopisek,0,dify,0,0);
MoveWindowRel(dwp,wFolder,0,dify,difx,0);
MoveWindowRel(dwp,wExport,difx,dify,0,0);
MoveWindowRel(dwp,wBrowse,difx,dify,0,0);
MoveWindowRel(dwp,wDDLFile,0,0,difx,0);
MoveWindowRel(dwp,wDDLBrowse,difx,0,0,0);
EndDeferWindowPos(dwp);
}
_dlgSize.cx=cx;
_dlgSize.cy=cy;
}
}
void CDDLReaderDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
CDialog::OnGetMinMaxInfo(lpMMI);
lpMMI->ptMinTrackSize.x=200;
lpMMI->ptMinTrackSize.y=150;
}
void CDDLReaderDlg::OnEnKillfocusDdlfile()
{
CString name;
wDDLFile.GetWindowText(name);
if (_ddlfile.OpenDDLFile(WString(name.GetString()))==false)
AfxMessageBox(IDS_FILEOPENFAILED);
UpdateList();
}
static CString GetGroupName(int group)
{
int id;
switch (group)
{
case 1: id= IDC_GROUP_GRAPHICS;break;
case 2: id= IDC_GROUP_SOUNDS;break;
case 3: id= IDC_GROUP_FONTS;break;
case 7: id= IDC_GROUP_BASIC;break;
case 8: id= IDC_GROUP_ITEMS;break;
case 9: id= IDC_GROUP_MONSTERS;break;
case 11: id= IDC_GROUP_DIALOGS;break;
case 0: id=IDC_GROUP_UNSPECIFIED;break;
default: id=IDC_GROUP_UNKNOWN;break;
}
CString res;
res.Format(id,group);
return res;
}
bool CDDLReaderDlg::File(WString name, int group, unsigned long offset)
{
LVITEM item;
CString grpname=GetGroupName(group);
wchar_t buff[40];
item.iItem=wFileList.GetItemCount();
item.iSubItem=0;
item.mask=LVIF_GROUPID|LVIF_TEXT;
item.iGroupId=group;
item.pszText=grpname.LockBuffer();
int ipos=wFileList.InsertItem(&item);
wFileList.SetItemText(ipos,1,name);
wFileList.SetItemText(ipos,3,_ui64tow(offset,buff,10));
grpname.UnlockBuffer();
return true;
}
void CDDLReaderDlg::UpdateList(void)
{
CString tmp;
wFileList.DeleteAllItems();
_ddlfile.EnumFiles(*this);
for (int i=0,cnt=wFileList.GetItemCount();i<cnt;i++)
{
unsigned long offset;
tmp=wFileList.GetItemText(i,3);
offset=_wtoi(tmp);
unsigned long size=_ddlfile.GetFileSize(offset);
if (size<1024)
tmp.Format(_T("%d B"),size);
else
tmp.Format(_T("%d KB"),(size+512)/1024);
wFileList.SetItemText(i,2,tmp);
}
}
void CDDLReaderDlg::OnBnClickedDdlbrowse()
{
CString fname;
wDDLFile.GetWindowText(fname);
CString ddlfilter;
ddlfilter.LoadString(IDS_DDLFILTER);
CFileDialog fdlg(TRUE,_T("DDL"),fname,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,ddlfilter);
if (fdlg.DoModal()==IDOK)
{
wDDLFile.SetWindowText(fdlg.GetPathName());
OnEnKillfocusDdlfile();
}
}
struct SortInfo
{
int index;
CListCtrl *list;
CString left;
CString right;
DDLFile *_ddlfile;
};
static int CALLBACK SortItemsInFileList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
SortInfo &sinfo=*(SortInfo *)lParamSort;
int res;
if (sinfo.index!=2)
{
sinfo.left=sinfo.list->GetItemText(lParam1,sinfo.index);
sinfo.right=sinfo.list->GetItemText(lParam2,sinfo.index);
switch (sinfo.index)
{
case 0:
case 1: res=wcsicmp(sinfo.left,sinfo.right);break;
case 3: {
int l=_wtoi(sinfo.left);
int r=_wtoi(sinfo.right);
res=(l>r)-(l<r);
}
}
}
else
{
sinfo.left=sinfo.list->GetItemText(lParam1,3);
sinfo.right=sinfo.list->GetItemText(lParam2,3);
unsigned long l=_wtoi(sinfo.left);
unsigned long r=_wtoi(sinfo.right);
l=sinfo._ddlfile->GetFileSize(l);
r=sinfo._ddlfile->GetFileSize(r);
res=(l>r)-(l<r);
}
if (res==0) res=(lParam1>lParam2)-(lParam1<lParam2);
return res;
}
void CDDLReaderDlg::OnLvnColumnclickFilelist(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
for (int i=0,cnt=wFileList.GetItemCount();i<cnt;i++)
wFileList.SetItemData(i,i);
SortInfo sinfo;
sinfo.index=pNMLV->iSubItem;
sinfo.list=&wFileList;
sinfo._ddlfile=&_ddlfile;
wFileList.SortItems(SortItemsInFileList,(LPARAM)&sinfo);
*pResult = 0;
}
static int WINAPI PosBrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
const wchar_t *curpath=(const wchar_t *)lpData;
if (uMsg == BFFM_INITIALIZED)
{
if (curpath && curpath[0])
{
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)((LPCSTR)curpath));
::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)((LPCSTR)curpath));
}
}
else if (uMsg == BFFM_SELCHANGED)
{
wchar_t buff[_MAX_PATH];
if (SHGetPathFromIDList((LPITEMIDLIST)lParam,buff))
{
::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)buff);
}
}
return 0;
};
static bool PathBrowser(HWND hWnd, wchar_t *path /* MAX_PATH size */)
{
BROWSEINFO brw;
memset(&brw,0,sizeof(brw));
brw.hwndOwner=hWnd;
brw.pidlRoot=NULL;
brw.pszDisplayName=path;
brw.lParam=(LPARAM)path;
brw.ulFlags= BIF_RETURNONLYFSDIRS |BIF_STATUSTEXT|BIF_USENEWUI ;
brw.lpfn = (BFFCALLBACK)(PosBrowseCallbackProc);
LPITEMIDLIST il=SHBrowseForFolder( &brw );
if (il==NULL) return false;
SHGetPathFromIDList(il,path);
IMalloc *shmalloc;
SHGetMalloc(&shmalloc);
shmalloc->Free(il);
if (path[0]==0) return false;
return true;
}
void CDDLReaderDlg::OnBnClickedBrowse()
{
wchar_t path[MAX_PATH];
wFolder.GetWindowText(path,MAX_PATH);
if (PathBrowser(*this,path))
{
wFolder.SetWindowText(path);
}
}
void CDDLReaderDlg::OnBnClickedExport()
{
wchar_t path[MAX_PATH];
wFolder.GetWindowText(path,MAX_PATH);
if (path[0]==0) OnBnClickedBrowse();
wFolder.GetWindowText(path,MAX_PATH);
if (path[0]==0) return;
WPathname fpath;
fpath.SetDirectory(path);
POSITION pos=wFileList.GetFirstSelectedItemPosition();
int max=wFileList.GetSelectedCount();
int cur=0;
DlgProgress pb;
if (max) {pb.Create(IDD_EXPORTING);pb.CenterWindow(this);EnableWindow(FALSE);}
while (pos)
{
MSG msg;
pb.wProgress.SetRange(0,max);
pb.wProgress.SetPos(++cur);
int i=wFileList.GetNextSelectedItem(pos);
CString fname;
unsigned long offset;
fname=wFileList.GetItemText(i,1);
offset=(unsigned long)_wtoi64(wFileList.GetItemText(i,3));
pb.wDesc.SetWindowText(fname);
if (PeekMessage(&msg,0,0,0,PM_NOREMOVE)==TRUE) AfxPumpMessage();
if (pb.stop) break;
DDLData data=_ddlfile.ExtractFile(offset);
if (data.data!=NULL)
{
fpath.SetFilename(fname);
HANDLE hFile=CreateFile(fpath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
while (hFile==INVALID_HANDLE_VALUE)
{
CString msg;
AfxFormatString1(msg,IDS_UNABLETOCREATEFILE,fpath);
int retry=AfxMessageBox(msg,MB_ABORTRETRYIGNORE);
if (retry==IDABORT) {EnableWindow(TRUE);return;}
if (retry==IDIGNORE) break;
hFile=CreateFile(fpath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
}
if (hFile!=INVALID_HANDLE_VALUE)
{
DWORD written;
WriteFile(hFile,data.data,data.sz,&written,NULL);
CloseHandle(hFile);
}
}
else
{
CString msg;
AfxFormatString1(msg,IDS_UNABLETOEXTACTDATA,fpath);
AfxMessageBox(msg,MB_OK|MB_ICONSTOP);
}
}
EnableWindow(TRUE);
}
WPathname CDDLReaderDlg::CreateTemp(int index)
{
if (!_lastTemp.IsNull()) DeleteFile(_lastTemp);
CString fname;
unsigned long offset;
fname=wFileList.GetItemText(index,1);
offset=(unsigned long)_wtoi64(wFileList.GetItemText(index,3));
_lastTemp.SetTempDirectory();
_lastTemp.SetFileTitle(WSC("SkeldalDDLReader"));
_lastTemp.SetExtension(WSC(".")+WString(fname));
DDLData data=_ddlfile.ExtractFile(offset);
if (data.data)
{
HANDLE hFile=CreateFile(_lastTemp,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
DWORD written;
WriteFile(hFile,data.data,data.sz,&written,NULL);
CloseHandle(hFile);
}
return _lastTemp;
}
void CDDLReaderDlg::OnNMDblclkFilelist(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
int index=wFileList.GetNextItem(-1,LVNI_FOCUSED);
WPathname pth=CreateTemp(index);
ShellExecute(*this,0,pth,0,0,SW_NORMAL);
}

76
DDLReader/DDLReaderDlg.h Normal file
View file

@ -0,0 +1,76 @@
// DDLReaderDlg.h : header file
//
#include "t:\h\atlmfc\include\afxwin.h"
#include "ddlfile.h"
#include "WPathname.h"
#if !defined(AFX_DDLREADERDLG_H__E765355F_0112_4B3E_90CE_111E28FE8EC6__INCLUDED_)
#define AFX_DDLREADERDLG_H__E765355F_0112_4B3E_90CE_111E28FE8EC6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderDlg dialog
class CDDLReaderDlg : public CDialog, public IDDLFileEnumerator
{
// Construction
CSize _dlgSize;
WPathname _lastTemp;
public:
CDDLReaderDlg(CWnd* pParent = NULL); // standard constructor
~CDDLReaderDlg();
// Dialog Data
//{{AFX_DATA(CDDLReaderDlg)
enum { IDD = IDD_DDLREADER_DIALOG };
CEdit wFolder;
CListCtrl wFileList;
CButton wBrowse;
CButton wExport;
CString vFolder;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDDLReaderDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CDDLReaderDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
CStatic wPopisek;
CEdit wDDLFile;
CButton wDDLBrowse;
afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI);
DDLFile _ddlfile;
afx_msg void OnEnKillfocusDdlfile();
void UpdateList(void);
virtual bool File(WString name, int group, unsigned long offset);
afx_msg void OnBnClickedDdlbrowse();
afx_msg void OnLvnColumnclickFilelist(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnBnClickedBrowse();
afx_msg void OnBnClickedExport();
afx_msg void OnNMDblclkFilelist(NMHDR *pNMHDR, LRESULT *pResult);
WPathname CreateTemp(int index);
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DDLREADERDLG_H__E765355F_0112_4B3E_90CE_111E28FE8EC6__INCLUDED_)

41
DDLReader/DlgProgress.cpp Normal file
View file

@ -0,0 +1,41 @@
// DlgProgress.cpp : implementation file
//
#include "stdafx.h"
#include "DDLReader.h"
#include "DlgProgress.h"
#include ".\dlgprogress.h"
// DlgProgress dialog
IMPLEMENT_DYNAMIC(DlgProgress, CDialog)
DlgProgress::DlgProgress(CWnd* pParent /*=NULL*/)
: CDialog(DlgProgress::IDD, pParent)
{
stop=false;
}
DlgProgress::~DlgProgress()
{
}
void DlgProgress::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS, wProgress);
DDX_Control(pDX, IDC_NAME, wDesc);
}
BEGIN_MESSAGE_MAP(DlgProgress, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()
// DlgProgress message handlers
void DlgProgress::OnBnClickedButton1()
{
stop=true;
}

28
DDLReader/DlgProgress.h Normal file
View file

@ -0,0 +1,28 @@
#pragma once
#include "t:\h\atlmfc\include\afxcmn.h"
#include "t:\h\atlmfc\include\afxwin.h"
// DlgProgress dialog
class DlgProgress : public CDialog
{
DECLARE_DYNAMIC(DlgProgress)
public:
DlgProgress(CWnd* pParent = NULL); // standard constructor
virtual ~DlgProgress();
// Dialog Data
enum { IDD = IDD_EXPORTING };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
CProgressCtrl wProgress;
CStatic wDesc;
afx_msg void OnBnClickedButton1();
bool stop;
};

View file

@ -0,0 +1,36 @@
#if !defined(AFX_IWSTRINGEFFECT_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_)
#define AFX_IWSTRINGEFFECT_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <wchar.h>
class IWStringEffect
{
public:
///function returns extra size that effect needs
/**
@param curSize size of string that enters to the effect
@return count of extra characters needs to effects;
*/
virtual unsigned long GetEffectExtraSize(unsigned long curSize) {return 0;}
///function renders begin of string.
/** Function returns number of characters rendered, and must be <= then size returned by GetEffectExtraSize()
@param renderPtr pointer to render buffer
@param curSize size of string that enters to the effect
@return number of characters rendered. Entered string will be rendered behind.
*/
virtual unsigned long PreRenderString(wchar_t *renderPtr,unsigned long curSize) {return 0;}
///function renders effect.
/**
@param renderPtr pointer to begin of render buffer.
@param rendered number of characters rendered by previous effect. Value doesn't point to the end
of buffer, function must add result of PreRenderString */
virtual void RenderString(wchar_t *renderPtr, unsigned long rendered)=0;
};
#endif

View file

@ -0,0 +1,93 @@
#include "stdafx.h"
#include ".\ddlfile.h"
DDLFile::DDLFile(void)
{
_hFile=0;
}
DDLFile::~DDLFile(void)
{
if (_hFile!=0) CloseHandle(_hFile);
}
bool DDLFile::OpenDDLFile(WString filename)
{
_hFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS,NULL);
if (_hFile==INVALID_HANDLE_VALUE)
{
_hFile=0;
return false;
}
return true;
}
bool DDLFile::ReadFile(void *data, size_t sz)
{
DWORD readed=0;
if (::ReadFile(_hFile,data,sz,&readed,NULL)==FALSE) return false;
if (readed!=sz) return false;
return true;
}
bool DDLFile::EnumFiles(IDDLFileEnumerator &enmClass)
{
unsigned long firstGroup;
unsigned long groupEndOffset;
unsigned long endGroups;
int i;
int ngroups;
SetFilePointer(_hFile,0,0,FILE_BEGIN);
if (ReadFile(&firstGroup,sizeof(firstGroup))==false) return false;
if (ReadFile(&groupEndOffset,sizeof(firstGroup))==false) return false;
unsigned long *group=(unsigned long *)alloca(groupEndOffset);
group[0]=firstGroup;
group[1]=groupEndOffset;
ngroups=groupEndOffset/8;
if (groupEndOffset!=8 && ReadFile(group+2,groupEndOffset-8)==false) return false;
SetFilePointer(_hFile,12,0,FILE_CURRENT);
if (ReadFile(&endGroups,sizeof(endGroups))==false) return false;
for (i=0;i<ngroups && group[i*2+1]<endGroups;i++);
ngroups=i;
WString fname;
for (i=0;i<ngroups;i++)
{
unsigned long endGroup=(i+1)<ngroups?group[i*2+3]:endGroups;
SetFilePointer(_hFile,group[i*2+1],0,FILE_BEGIN);
unsigned long pos=group[i*2+1];
while (pos<endGroup)
{
char buff[13];
unsigned long offset;
if (ReadFile(buff,12)==false) return false;
if (ReadFile(&offset,4)==false) return false;
buff[12]=0;
fname.SetUTF8(buff);
enmClass.File(fname,group[i*2],offset);
pos+=12+4;
}
}
return true;
}
unsigned long DDLFile::GetFileSize(unsigned long offset)
{
unsigned long sz=0;
SetFilePointer(_hFile,offset,0,FILE_BEGIN);
ReadFile(&sz,4);
return sz;
}
DDLData DDLFile::ExtractFile(unsigned long offset)
{
SetFilePointer(_hFile,offset,0,FILE_BEGIN);
DDLData data;
if (ReadFile(&data.sz,4)==false) return DDLData();
data.data=malloc(data.sz);
if (ReadFile(data.data,data.sz)==false) return DDLData();
return data;
}

View file

@ -0,0 +1,45 @@
#pragma once
#include "WString.h"
class IDDLFileEnumerator
{
public:
virtual bool File(WString name, int group, unsigned long offset)=0;
};
struct DDLData
{
void *data;
size_t sz;
DDLData():data(0),sz(0) {}
~DDLData() {free(data);}
DDLData(const DDLData &other):data(other.data),sz(other.sz)
{
DDLData &dother=const_cast<DDLData &>(other);
dother.data=0;dother.sz=0;
}
DDLData& operator =(const DDLData &other)
{
DDLData &dother=const_cast<DDLData &>(other);
data=other.data;sz=other.sz;
dother.data=0;dother.sz=0;
return *this;
}
};
class DDLFile
{
HANDLE _hFile;
bool ReadFile(void *data, size_t sz);
public:
DDLFile(void);
~DDLFile(void);
bool OpenDDLFile(WString filename);
bool EnumFiles(IDDLFileEnumerator &enmClass);
DDLData ExtractFile(unsigned long offset);
unsigned long GetFileSize(unsigned long offset);
};

View file

@ -0,0 +1,67 @@
// DDLReader.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "DDLReader.h"
#include "DDLReaderDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp
BEGIN_MESSAGE_MAP(CDDLReaderApp, CWinApp)
//{{AFX_MSG_MAP(CDDLReaderApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp construction
CDDLReaderApp::CDDLReaderApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDDLReaderApp object
CDDLReaderApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp initialization
BOOL CDDLReaderApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
CDDLReaderDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

View file

@ -0,0 +1,49 @@
// DDLReader.h : main header file for the DDLREADER application
//
#if !defined(AFX_DDLREADER_H__9FE8F7F8_112D_4735_A4BA_5141A991D609__INCLUDED_)
#define AFX_DDLREADER_H__9FE8F7F8_112D_4735_A4BA_5141A991D609__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderApp:
// See DDLReader.cpp for the implementation of this class
//
class CDDLReaderApp : public CWinApp
{
public:
CDDLReaderApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDDLReaderApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CDDLReaderApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DDLREADER_H__9FE8F7F8_112D_4735_A4BA_5141A991D609__INCLUDED_)

View file

@ -0,0 +1,278 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Czech resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CSY)
#ifdef _WIN32
LANGUAGE LANG_CZECH, SUBLANG_DEFAULT
#pragma code_page(1250)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\DDLReader.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\DDLReader.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_EXPORTING DIALOGEX 0, 0, 186, 82
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE |
WS_CAPTION | WS_SYSMENU
CAPTION "Exporting"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER | 0x1,7,39,
172,14
CTEXT "Exporting",IDC_STATIC,7,7,172,8
CTEXT "Static",IDC_NAME,7,23,172,8
PUSHBUTTON "Stop",IDC_BUTTON1,68,61,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_EXPORTING, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 179
TOPMARGIN, 7
BOTTOMMARGIN, 75
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_ABOUTBOX "&About DDLReader..."
IDS_FILEOPENFAILED "Failed to open DDL"
IDC_HEADGROUP "Group"
IDC_HEADFNAME "Filename"
IDC_HEADSIZE "Size"
IDC_HEADOFFSET "Offset"
IDS_DDLFILTER "DDLFiles|*.ddl|All Files|*.*||"
IDC_GROUP_GRAPHICS "Graphics"
IDC_GROUP_SOUNDS "Sounds"
IDC_GROUP_FONTS "Fonts"
IDC_GROUP_BASIC "Basic graphics"
END
STRINGTABLE
BEGIN
IDC_GROUP_ITEMS "Item graphics"
IDC_GROUP_MONSTERS "Monster graphics"
IDC_GROUP_DIALOGS "Dialog graphics"
IDC_GROUP_UNSPECIFIED "Unspecified"
IDC_GROUP_UNKNOWN "Unknown (%d)"
IDS_UNABLETOCREATEFILE "Unable to create target file: \r\n%1"
IDS_UNABLETOEXTACTDATA "Unable to extract data. General reading error"
END
#endif // Czech resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About DDLReader"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "DDLReader Version 1.0",IDC_STATIC,40,10,119,8,
SS_NOPREFIX
LTEXT "Copyright (C) 2005",IDC_STATIC,40,25,119,8
DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP
END
IDD_DDLREADER_DIALOG DIALOGEX 0, 0, 364, 262
STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_CAPTION |
WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "DDLReader"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL "List2",IDC_FILELIST,"SysListView32",LVS_REPORT |
LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,0,14,363,219
LTEXT "Export to folder:",IDC_POPISEK,0,235,50,8
EDITTEXT IDC_FOLDER,0,248,263,14,ES_AUTOHSCROLL
PUSHBUTTON "Browse",IDC_BROWSE,268,248,34,14
PUSHBUTTON "Export",IDC_EXPORT,306,248,58,14
EDITTEXT IDC_DDLFILE,0,0,313,12,ES_AUTOHSCROLL
PUSHBUTTON "Browse DDL",IDC_DDLBROWSE,314,0,50,12
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "FileDescription", "DDLReader MFC Application"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "DDLReader"
VALUE "LegalCopyright", "Copyright (C) 2005"
VALUE "OriginalFilename", "DDLReader.EXE"
VALUE "ProductName", "DDLReader Application"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
IDD_DDLREADER_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 357
TOPMARGIN, 7
BOTTOMMARGIN, 255
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\DDLReader.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View file

@ -0,0 +1,34 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DDLReader", "DDLReader.vcproj", "{A5326507-3420-4D03-B9EB-5583790B412B}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SourceCodeControl) = preSolution
SccNumberOfProjects = 2
SccProjectName0 = \u0022$/Skeldal/DDLReader\u0022,\u0020NJEAAAAA
SccLocalPath0 = ..\\..\\..
SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
CanCheckoutShared = false
SccProjectFilePathRelativizedFromConnection0 = Projects\\Skeldal\\DDLReader\\
SolutionUniqueID = {A1A5598F-1F71-475C-8CAA-699B487DC20F}
SccProjectUniqueName1 = DDLReader.vcproj
SccLocalPath1 = ..\\..\\..
CanCheckoutShared = false
SccProjectFilePathRelativizedFromConnection1 = Projects\\Skeldal\\DDLReader\\
EndGlobalSection
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{A5326507-3420-4D03-B9EB-5583790B412B}.Debug.ActiveCfg = Debug|Win32
{A5326507-3420-4D03-B9EB-5583790B412B}.Debug.Build.0 = Debug|Win32
{A5326507-3420-4D03-B9EB-5583790B412B}.Release.ActiveCfg = Release|Win32
{A5326507-3420-4D03-B9EB-5583790B412B}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,291 @@
<?xml version="1.0" encoding="windows-1250"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="DDLReader"
ProjectGUID="{A5326507-3420-4D03-B9EB-5583790B412B}"
SccProjectName="&quot;$/Skeldal/DDLReader&quot;, NJEAAAAA"
SccAuxPath=""
SccLocalPath="..\..\.."
SccProvider="MSSCCI:Microsoft Visual SourceSafe"
Keyword="MFCProj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="2"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="1">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Release/DDLReader.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Release/DDLReader.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
ProgramDatabaseFile=".\Release/DDLReader.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Release/DDLReader.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1029"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="2"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="1">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Debug/DDLReader.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile=".\Debug/DDLReader.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/DDLReader.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/DDLReader.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1029"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\DDLFile.cpp">
</File>
<File
RelativePath=".\DDLReader.cpp">
</File>
<File
RelativePath=".\DDLReader.rc">
</File>
<File
RelativePath=".\DDLReaderDlg.cpp">
</File>
<File
RelativePath=".\DlgProgress.cpp">
</File>
<File
RelativePath=".\StdAfx.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WPathname.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WString.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WStringMemory.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\WStringProxy.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath=".\DDLFile.h">
</File>
<File
RelativePath=".\DDLReader.h">
</File>
<File
RelativePath=".\DDLReaderDlg.h">
</File>
<File
RelativePath=".\DlgProgress.h">
</File>
<File
RelativePath=".\IWStringEffect.h">
</File>
<File
RelativePath=".\resource.h">
</File>
<File
RelativePath=".\StdAfx.h">
</File>
<File
RelativePath=".\WPathname.h">
</File>
<File
RelativePath=".\WString.h">
</File>
<File
RelativePath=".\WStringMemory.h">
</File>
<File
RelativePath=".\WStringProxy.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File
RelativePath=".\res\DDLReader.ico">
</File>
</Filter>
</Files>
<Globals>
<Global
Name="RESOURCE_FILE"
Value="DDLReader.rc"/>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,533 @@
// DDLReaderDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DDLReader.h"
#include "DDLReaderDlg.h"
#include ".\ddlreaderdlg.h"
#include "WPathname.h"
#include "DlgProgress.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderDlg dialog
CDDLReaderDlg::CDDLReaderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDDLReaderDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDDLReaderDlg)
vFolder = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CDDLReaderDlg::~CDDLReaderDlg()
{
if (!_lastTemp.IsNull()) DeleteFile(_lastTemp);
}
void CDDLReaderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDDLReaderDlg)
DDX_Control(pDX, IDC_FOLDER, wFolder);
DDX_Control(pDX, IDC_FILELIST, wFileList);
DDX_Control(pDX, IDC_BROWSE, wBrowse);
DDX_Control(pDX, IDC_EXPORT, wExport);
DDX_Text(pDX, IDC_FOLDER, vFolder);
DDX_Control(pDX, IDC_POPISEK, wPopisek);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_DDLFILE, wDDLFile);
DDX_Control(pDX, IDC_DDLBROWSE, wDDLBrowse);
}
BEGIN_MESSAGE_MAP(CDDLReaderDlg, CDialog)
//{{AFX_MSG_MAP(CDDLReaderDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
ON_EN_KILLFOCUS(IDC_DDLFILE, OnEnKillfocusDdlfile)
ON_BN_CLICKED(IDC_DDLBROWSE, OnBnClickedDdlbrowse)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_FILELIST, OnLvnColumnclickFilelist)
ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
ON_BN_CLICKED(IDC_EXPORT, OnBnClickedExport)
ON_NOTIFY(NM_DBLCLK, IDC_FILELIST, OnNMDblclkFilelist)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderDlg message handlers
BOOL CDDLReaderDlg::OnInitDialog()
{
CRect rc;
GetClientRect(&rc);
_dlgSize=rc.Size();
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString header;
header.LoadString(IDC_HEADGROUP);
wFileList.InsertColumn(0,header,LVCFMT_CENTER,100,0);
header.LoadString(IDC_HEADFNAME);
wFileList.InsertColumn(1,header,LVCFMT_LEFT,140,1);
header.LoadString(IDC_HEADSIZE);
wFileList.InsertColumn(2,header,LVCFMT_RIGHT,80,2);
header.LoadString(IDC_HEADOFFSET);
wFileList.InsertColumn(3,header,LVCFMT_RIGHT,80,3);
ListView_SetExtendedListViewStyleEx(wFileList,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDDLReaderDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDDLReaderDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDDLReaderDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void MoveWindowRel(HDWP &hdwp, CWnd &wnd, int xr,int yr, int xs, int ys)
{
CRect rc;
wnd.GetWindowRect(&rc);
wnd.GetParent()->ScreenToClient(&rc);
rc.left+=xr;
rc.top+=yr;
rc.bottom+=yr+ys;
rc.right+=xr+xs;
hdwp=DeferWindowPos(hdwp,wnd,NULL,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,SWP_NOZORDER);
}
void CDDLReaderDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (nType!=SIZE_MINIMIZED)
{
if (wFileList.GetSafeHwnd()!=0)
{
HDWP dwp=BeginDeferWindowPos(10);
int difx=cx-_dlgSize.cx;
int dify=cy-_dlgSize.cy;
MoveWindowRel(dwp,wFileList,0,0,difx,dify);
MoveWindowRel(dwp,wPopisek,0,dify,0,0);
MoveWindowRel(dwp,wFolder,0,dify,difx,0);
MoveWindowRel(dwp,wExport,difx,dify,0,0);
MoveWindowRel(dwp,wBrowse,difx,dify,0,0);
MoveWindowRel(dwp,wDDLFile,0,0,difx,0);
MoveWindowRel(dwp,wDDLBrowse,difx,0,0,0);
EndDeferWindowPos(dwp);
}
_dlgSize.cx=cx;
_dlgSize.cy=cy;
}
}
void CDDLReaderDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
CDialog::OnGetMinMaxInfo(lpMMI);
lpMMI->ptMinTrackSize.x=200;
lpMMI->ptMinTrackSize.y=150;
}
void CDDLReaderDlg::OnEnKillfocusDdlfile()
{
CString name;
wDDLFile.GetWindowText(name);
if (_ddlfile.OpenDDLFile(WString(name.GetString()))==false)
AfxMessageBox(IDS_FILEOPENFAILED);
UpdateList();
}
static CString GetGroupName(int group)
{
int id;
switch (group)
{
case 1: id= IDC_GROUP_GRAPHICS;break;
case 2: id= IDC_GROUP_SOUNDS;break;
case 3: id= IDC_GROUP_FONTS;break;
case 7: id= IDC_GROUP_BASIC;break;
case 8: id= IDC_GROUP_ITEMS;break;
case 9: id= IDC_GROUP_MONSTERS;break;
case 11: id= IDC_GROUP_DIALOGS;break;
case 0: id=IDC_GROUP_UNSPECIFIED;break;
default: id=IDC_GROUP_UNKNOWN;break;
}
CString res;
res.Format(id,group);
return res;
}
bool CDDLReaderDlg::File(WString name, int group, unsigned long offset)
{
LVITEM item;
CString grpname=GetGroupName(group);
wchar_t buff[40];
item.iItem=wFileList.GetItemCount();
item.iSubItem=0;
item.mask=LVIF_GROUPID|LVIF_TEXT;
item.iGroupId=group;
item.pszText=grpname.LockBuffer();
int ipos=wFileList.InsertItem(&item);
wFileList.SetItemText(ipos,1,name);
wFileList.SetItemText(ipos,3,_ui64tow(offset,buff,10));
grpname.UnlockBuffer();
return true;
}
void CDDLReaderDlg::UpdateList(void)
{
CString tmp;
wFileList.DeleteAllItems();
_ddlfile.EnumFiles(*this);
for (int i=0,cnt=wFileList.GetItemCount();i<cnt;i++)
{
unsigned long offset;
tmp=wFileList.GetItemText(i,3);
offset=_wtoi(tmp);
unsigned long size=_ddlfile.GetFileSize(offset);
if (size<1024)
tmp.Format(_T("%d B"),size);
else
tmp.Format(_T("%d KB"),(size+512)/1024);
wFileList.SetItemText(i,2,tmp);
}
}
void CDDLReaderDlg::OnBnClickedDdlbrowse()
{
CString fname;
wDDLFile.GetWindowText(fname);
CString ddlfilter;
ddlfilter.LoadString(IDS_DDLFILTER);
CFileDialog fdlg(TRUE,_T("DDL"),fname,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,ddlfilter);
if (fdlg.DoModal()==IDOK)
{
wDDLFile.SetWindowText(fdlg.GetPathName());
OnEnKillfocusDdlfile();
}
}
struct SortInfo
{
int index;
CListCtrl *list;
CString left;
CString right;
DDLFile *_ddlfile;
};
static int CALLBACK SortItemsInFileList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
SortInfo &sinfo=*(SortInfo *)lParamSort;
int res;
if (sinfo.index!=2)
{
sinfo.left=sinfo.list->GetItemText(lParam1,sinfo.index);
sinfo.right=sinfo.list->GetItemText(lParam2,sinfo.index);
switch (sinfo.index)
{
case 0:
case 1: res=wcsicmp(sinfo.left,sinfo.right);break;
case 3: {
int l=_wtoi(sinfo.left);
int r=_wtoi(sinfo.right);
res=(l>r)-(l<r);
}
}
}
else
{
sinfo.left=sinfo.list->GetItemText(lParam1,3);
sinfo.right=sinfo.list->GetItemText(lParam2,3);
unsigned long l=_wtoi(sinfo.left);
unsigned long r=_wtoi(sinfo.right);
l=sinfo._ddlfile->GetFileSize(l);
r=sinfo._ddlfile->GetFileSize(r);
res=(l>r)-(l<r);
}
if (res==0) res=(lParam1>lParam2)-(lParam1<lParam2);
return res;
}
void CDDLReaderDlg::OnLvnColumnclickFilelist(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
for (int i=0,cnt=wFileList.GetItemCount();i<cnt;i++)
wFileList.SetItemData(i,i);
SortInfo sinfo;
sinfo.index=pNMLV->iSubItem;
sinfo.list=&wFileList;
sinfo._ddlfile=&_ddlfile;
wFileList.SortItems(SortItemsInFileList,(LPARAM)&sinfo);
*pResult = 0;
}
static int WINAPI PosBrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
const wchar_t *curpath=(const wchar_t *)lpData;
if (uMsg == BFFM_INITIALIZED)
{
if (curpath && curpath[0])
{
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)((LPCSTR)curpath));
::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)((LPCSTR)curpath));
}
}
else if (uMsg == BFFM_SELCHANGED)
{
wchar_t buff[_MAX_PATH];
if (SHGetPathFromIDList((LPITEMIDLIST)lParam,buff))
{
::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)buff);
}
}
return 0;
};
static bool PathBrowser(HWND hWnd, wchar_t *path /* MAX_PATH size */)
{
BROWSEINFO brw;
memset(&brw,0,sizeof(brw));
brw.hwndOwner=hWnd;
brw.pidlRoot=NULL;
brw.pszDisplayName=path;
brw.lParam=(LPARAM)path;
brw.ulFlags= BIF_RETURNONLYFSDIRS |BIF_STATUSTEXT|BIF_USENEWUI ;
brw.lpfn = (BFFCALLBACK)(PosBrowseCallbackProc);
LPITEMIDLIST il=SHBrowseForFolder( &brw );
if (il==NULL) return false;
SHGetPathFromIDList(il,path);
IMalloc *shmalloc;
SHGetMalloc(&shmalloc);
shmalloc->Free(il);
if (path[0]==0) return false;
return true;
}
void CDDLReaderDlg::OnBnClickedBrowse()
{
wchar_t path[MAX_PATH];
wFolder.GetWindowText(path,MAX_PATH);
if (PathBrowser(*this,path))
{
wFolder.SetWindowText(path);
}
}
void CDDLReaderDlg::OnBnClickedExport()
{
wchar_t path[MAX_PATH];
wFolder.GetWindowText(path,MAX_PATH);
if (path[0]==0) OnBnClickedBrowse();
wFolder.GetWindowText(path,MAX_PATH);
if (path[0]==0) return;
WPathname fpath;
fpath.SetDirectory(path);
POSITION pos=wFileList.GetFirstSelectedItemPosition();
int max=wFileList.GetSelectedCount();
int cur=0;
DlgProgress pb;
if (max) {pb.Create(IDD_EXPORTING);pb.CenterWindow(this);EnableWindow(FALSE);}
while (pos)
{
MSG msg;
pb.wProgress.SetRange(0,max);
pb.wProgress.SetPos(++cur);
int i=wFileList.GetNextSelectedItem(pos);
CString fname;
unsigned long offset;
fname=wFileList.GetItemText(i,1);
offset=(unsigned long)_wtoi64(wFileList.GetItemText(i,3));
pb.wDesc.SetWindowText(fname);
if (PeekMessage(&msg,0,0,0,PM_NOREMOVE)==TRUE) AfxPumpMessage();
if (pb.stop) break;
DDLData data=_ddlfile.ExtractFile(offset);
if (data.data!=NULL)
{
fpath.SetFilename(fname);
HANDLE hFile=CreateFile(fpath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
while (hFile==INVALID_HANDLE_VALUE)
{
CString msg;
AfxFormatString1(msg,IDS_UNABLETOCREATEFILE,fpath);
int retry=AfxMessageBox(msg,MB_ABORTRETRYIGNORE);
if (retry==IDABORT) {EnableWindow(TRUE);return;}
if (retry==IDIGNORE) break;
hFile=CreateFile(fpath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
}
if (hFile!=INVALID_HANDLE_VALUE)
{
DWORD written;
WriteFile(hFile,data.data,data.sz,&written,NULL);
CloseHandle(hFile);
}
}
else
{
CString msg;
AfxFormatString1(msg,IDS_UNABLETOEXTACTDATA,fpath);
AfxMessageBox(msg,MB_OK|MB_ICONSTOP);
}
}
EnableWindow(TRUE);
}
WPathname CDDLReaderDlg::CreateTemp(int index)
{
if (!_lastTemp.IsNull()) DeleteFile(_lastTemp);
CString fname;
unsigned long offset;
fname=wFileList.GetItemText(index,1);
offset=(unsigned long)_wtoi64(wFileList.GetItemText(index,3));
_lastTemp.SetTempDirectory();
_lastTemp.SetFileTitle(WSC("SkeldalDDLReader"));
_lastTemp.SetExtension(WSC(".")+WString(fname));
DDLData data=_ddlfile.ExtractFile(offset);
if (data.data)
{
HANDLE hFile=CreateFile(_lastTemp,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
DWORD written;
WriteFile(hFile,data.data,data.sz,&written,NULL);
CloseHandle(hFile);
}
return _lastTemp;
}
void CDDLReaderDlg::OnNMDblclkFilelist(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
int index=wFileList.GetNextItem(-1,LVNI_FOCUSED);
WPathname pth=CreateTemp(index);
ShellExecute(*this,0,pth,0,0,SW_NORMAL);
}

View file

@ -0,0 +1,76 @@
// DDLReaderDlg.h : header file
//
#include "t:\h\atlmfc\include\afxwin.h"
#include "ddlfile.h"
#include "WPathname.h"
#if !defined(AFX_DDLREADERDLG_H__E765355F_0112_4B3E_90CE_111E28FE8EC6__INCLUDED_)
#define AFX_DDLREADERDLG_H__E765355F_0112_4B3E_90CE_111E28FE8EC6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CDDLReaderDlg dialog
class CDDLReaderDlg : public CDialog, public IDDLFileEnumerator
{
// Construction
CSize _dlgSize;
WPathname _lastTemp;
public:
CDDLReaderDlg(CWnd* pParent = NULL); // standard constructor
~CDDLReaderDlg();
// Dialog Data
//{{AFX_DATA(CDDLReaderDlg)
enum { IDD = IDD_DDLREADER_DIALOG };
CEdit wFolder;
CListCtrl wFileList;
CButton wBrowse;
CButton wExport;
CString vFolder;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDDLReaderDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CDDLReaderDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
CStatic wPopisek;
CEdit wDDLFile;
CButton wDDLBrowse;
afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI);
DDLFile _ddlfile;
afx_msg void OnEnKillfocusDdlfile();
void UpdateList(void);
virtual bool File(WString name, int group, unsigned long offset);
afx_msg void OnBnClickedDdlbrowse();
afx_msg void OnLvnColumnclickFilelist(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnBnClickedBrowse();
afx_msg void OnBnClickedExport();
afx_msg void OnNMDblclkFilelist(NMHDR *pNMHDR, LRESULT *pResult);
WPathname CreateTemp(int index);
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DDLREADERDLG_H__E765355F_0112_4B3E_90CE_111E28FE8EC6__INCLUDED_)

View file

@ -0,0 +1,41 @@
// DlgProgress.cpp : implementation file
//
#include "stdafx.h"
#include "DDLReader.h"
#include "DlgProgress.h"
#include ".\dlgprogress.h"
// DlgProgress dialog
IMPLEMENT_DYNAMIC(DlgProgress, CDialog)
DlgProgress::DlgProgress(CWnd* pParent /*=NULL*/)
: CDialog(DlgProgress::IDD, pParent)
{
stop=false;
}
DlgProgress::~DlgProgress()
{
}
void DlgProgress::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS, wProgress);
DDX_Control(pDX, IDC_NAME, wDesc);
}
BEGIN_MESSAGE_MAP(DlgProgress, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()
// DlgProgress message handlers
void DlgProgress::OnBnClickedButton1()
{
stop=true;
}

View file

@ -0,0 +1,28 @@
#pragma once
#include "t:\h\atlmfc\include\afxcmn.h"
#include "t:\h\atlmfc\include\afxwin.h"
// DlgProgress dialog
class DlgProgress : public CDialog
{
DECLARE_DYNAMIC(DlgProgress)
public:
DlgProgress(CWnd* pParent = NULL); // standard constructor
virtual ~DlgProgress();
// Dialog Data
enum { IDD = IDD_EXPORTING };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
CProgressCtrl wProgress;
CStatic wDesc;
afx_msg void OnBnClickedButton1();
bool stop;
};

View file

@ -0,0 +1,36 @@
#if !defined(AFX_IWSTRINGEFFECT_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_)
#define AFX_IWSTRINGEFFECT_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <wchar.h>
class IWStringEffect
{
public:
///function returns extra size that effect needs
/**
@param curSize size of string that enters to the effect
@return count of extra characters needs to effects;
*/
virtual unsigned long GetEffectExtraSize(unsigned long curSize) {return 0;}
///function renders begin of string.
/** Function returns number of characters rendered, and must be <= then size returned by GetEffectExtraSize()
@param renderPtr pointer to render buffer
@param curSize size of string that enters to the effect
@return number of characters rendered. Entered string will be rendered behind.
*/
virtual unsigned long PreRenderString(wchar_t *renderPtr,unsigned long curSize) {return 0;}
///function renders effect.
/**
@param renderPtr pointer to begin of render buffer.
@param rendered number of characters rendered by previous effect. Value doesn't point to the end
of buffer, function must add result of PreRenderString */
virtual void RenderString(wchar_t *renderPtr, unsigned long rendered)=0;
};
#endif

View file

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// DDLReader.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

View file

@ -0,0 +1,27 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__C5BDACC6_729E_4CA2_B27E_A1F209FB32A7__INCLUDED_)
#define AFX_STDAFX_H__C5BDACC6_729E_4CA2_B27E_A1F209FB32A7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include "wstring.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__C5BDACC6_729E_4CA2_B27E_A1F209FB32A7__INCLUDED_)

View file

@ -0,0 +1,408 @@
// WPathname.cpp: implementation of the WPathname class.
//
//////////////////////////////////////////////////////////////////////
#include "WPathname.h"
#include <windows.h>
#include <shlobj.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
WPathname::WPathname(const wchar_t *name /*=NULL*/)
{
if (name) SetPathname(name);
}
WPathname::WPathname(const WString &name)
{
SetPathname(name);
}
WPathname::WPathname(const wchar_t *relpath, const WPathname &abspath)
{
_fullpath=WString(relpath);
int chr=_fullpath.FindLast('\\');
if (chr!=-1)
{
_path=_fullpath.Left(chr+1);
_filetitle=_fullpath.Right(chr+1);
}
else
{
_filetitle=_fullpath;
}
chr=_filetitle.FindLast('.');
if (chr!=-1)
{
_extension=_filetitle.Right(chr);
_filetitle=_filetitle.Left(chr);
}
RelativeToFull(abspath);
}
WPathname::WPathname(const WPathname &other)
{
_fullpath=other._fullpath;
_path=other._path;
_filetitle=other._filetitle;
_extension=other._extension;
}
void WPathname::SetDrive(wchar_t dr)
{
if (HasDrive())
{
if (dr==0) _path=_path.Right(2);
else _path[0]=dr;
}
else if (dr!=0)
{
int np=IsNetworkPath();
wchar_t buff[2];
buff[0]=dr;
buff[1]=':';
buff[2]=0;
if (np)
_path=WString(buff)+_path.Right(np);
else
_path=WString(buff)+_path;
}
RebuildPath();
}
void WPathname::SetDirectory(const wchar_t *dir)
{
bool copydrv; //directory doesn't contain drive, need copy from original
bool addslash; //directory doesn't ending by backslash, need add it
int len=wcslen(dir);
copydrv=HasDrive(dir) || !HasDrive(); //copy original drive, if exists and directory doesn't contaion drive
if (wcsncmp(dir,L"\\\\",2)==0) copydrv=true; //network path, don't copy drive
addslash=len && dir[len-1]!='\\'; //add slash
if (copydrv)
_path=WString(dir);
else
_path=_path.Left(2)+WString(dir);
if (addslash)
_path+=WSC("\\");
RebuildPath();
}
void WPathname::SetFilename(const wchar_t *filename)
{
WString wfilename=WString(filename);
int dot=wfilename.FindLast('.');
if (dot==-1)
{
_filetitle=wfilename;
_extension=0;
}
else
{
_filetitle=wfilename.Left(dot);
_extension=wfilename.Right(dot);
}
RebuildPath();
}
void WPathname::SetExtension(const wchar_t *ext)
{
_extension=WString(ext);
RebuildPath();
}
void WPathname::SetFileTitle(const wchar_t *title)
{
_filetitle=WString(title);
RebuildPath();
}
void WPathname::SetPathname(const wchar_t *pathname)
{
SetPathname(WString(pathname));
}
void WPathname::SetPathname(const WString &pathname)
{
if (pathname.GetLength()==0) SetNull();
else
{
wchar_t *part;
DWORD needsz=GetFullPathNameW(pathname,0,NULL,&part);
wchar_t *fpth=(wchar_t *)alloca(needsz*sizeof(*fpth));
GetFullPathNameW(pathname,needsz,fpth,&part);
part=wcsrchr(fpth,'\\');
if (part) part++;else part=NULL;
if (part)
{
SetFilename(part);
*part=0;
}
else
SetFilename(WString());
SetDirectory(fpth);
}
}
const wchar_t *WPathname::GetNameFromPath(const wchar_t *path)
{
const wchar_t *c=wcsrchr(path,'\\');
if (c!=NULL) c++;else return path;
return c;
}
const wchar_t *WPathname::GetExtensionFromPath(const wchar_t *path)
{
const wchar_t *fname=GetNameFromPath(path);
const wchar_t *c=wcsrchr(fname,'.');
if (c==NULL) c=wcsrchr(path,0);
return c;
}
void WPathname::RebuildPath()
{
_fullpath=_path+_filetitle+_extension;
}
bool WPathname::GetDirectoryWithDriveWLBS(wchar_t *buff, size_t size) const
{
size_t psize=wcslen(GetDirectoryWithDrive());
if (psize>size) return false;
if (psize==0) {buff[0]=0;return true;}
wcsncpy(buff,GetDirectoryWithDrive(),psize-1);
buff[psize-1]=0;
return true;
}
WString WPathname::GetDirectoryWithDriveWLBS() const
{
if (_path.GetLength()) return _path.Left(_path.GetLength()-1);
return WString();
}
bool WPathname::IsPathValid() const
{
if (IsNull()) return false;
wchar_t *invalidChars=L"/*?\"<>|";
const wchar_t *path=GetFullPath();
if (*path==0) return false;
while (*path)
{
if (wcschr(invalidChars,*path)!=NULL) return false;
path++;
}
return true;
}
bool WPathname::SetTempDirectory()
{
wchar_t buff[1];
DWORD size=GetTempPathW(1,buff);
if (size==0) return false;
WString pth;
wchar_t *p=pth.CreateBuffer(size);
if (GetTempPathW(size,p)==0) return false;
pth.UnlockBuffer();
_path=pth;
return true;
}
bool WPathname::SetDirectorySpecial(int nSpecCode)
{
wchar_t buff[MAX_PATH];
if (SHGetSpecialFolderPathW(GetForegroundWindow(),buff,nSpecCode,FALSE)!=NOERROR) return false;
SetDirectory(buff);
return true;
}
bool WPathname::SetTempFile(const wchar_t *prefix, unsigned int unique)
{
wchar_t tempname[MAX_PATH];
if (GetTempFileNameW(GetDirectoryWithDrive(),prefix,unique,tempname)==0) return false;
this->SetPathname(tempname);
return true;
}
WPathname WPathname::GetExePath()
{
wchar_t buff[MAX_PATH*4];
GetModuleFileNameW(NULL,buff,sizeof(buff));
return WPathname(buff);
}
const wchar_t *WPathname::FullToRelativeProjectRoot(const wchar_t *full, const wchar_t *projectRoot)
{
const wchar_t *a=full,*b=projectRoot;
while (*a && towlower(*a)==towlower(*b)) {a++;b++;};
if (*b) return full;
return a;
}
bool WPathname::FullToRelative(const WPathname &relativeto)
{
if (relativeto.IsNull() || IsNull()) return false;
bool h1=HasDrive();
bool h2=relativeto.HasDrive();
if (h1!=h2) return false; //rozdilny zpusob adresace - nelze vytvorit relatvni cestu
if (h1==true && h2==true && towupper(GetDrive())!=towupper(relativeto.GetDrive()))
return false; //ruzne disky, nelze vytvorit relativni cestu
if (wcsncmp(_path,L"\\\\",2)==0) //sitova cesta
{
int slsh=0; //citac lomitek
const wchar_t *a=_path;
const wchar_t *b=relativeto._path;
while (towupper(*a)==towupper(*b) && *a && slsh<3) //zacatek sitove cesty musi byt stejny
{
if (*a=='\\') slsh++;
a++;b++;
}
if (slsh!=3) return false; //pokud neni stejny, nelze vytvorit relativni cestu
}
int sublevel=0;
const wchar_t *ps1=_path;
const wchar_t *ps2=relativeto._path;
if (h1) {ps1+=2;ps2+=2;}
const wchar_t *sls=ps2;
while (towupper(*ps1)==towupper(*ps2) && *ps1)
{
if (*ps2=='\\') sls=ps2+1;
ps1++;ps2++;
}
ps1-=ps2-sls;
if (sls)
{
while (sls=wcschr(sls,'\\'))
{
sls++;
sublevel++;
}
}
wchar_t *buff=(wchar_t *)alloca((sublevel*3+wcslen(ps1)+1)*sizeof(*buff));
wchar_t *pos=buff;
for (int i=0;i<sublevel;i++)
{wcscpy(pos,L"..\\");pos+=3;}
wcscpy(pos,ps1);
SetDrive(0);
SetDirectory(buff);
return true;
}
bool WPathname::RelativeToFull(const WPathname &ref)
{
if (ref.IsNull() || IsNull()) return false;
const wchar_t *beg;
if (HasDrive())
if (towupper(GetDrive())!=towupper(ref.GetDrive())) return false;
else beg=_path+2;
else beg=_path;
const wchar_t *end=wcschr(ref._path,0);
if (beg[0]=='\\')
{
int np;
if (ref.HasDrive()) end=ref._path+2;
else if (np=ref.IsNetworkPath()) end=ref._path+np;
else end=ref._path;
}
else while (wcsncmp(beg,L"..\\",3)==0 || wcsncmp(beg,L".\\",2)==0)
{
if (beg[1]=='.')
{
if (end>ref._path.GetString())
{
end--;
while (end>ref._path.GetString() && end[-1]!='\\') end--;
}
beg+=3;
}
else
beg+=2;
}
int partln=end-ref._path;
wchar_t *buff=(wchar_t *)alloca((partln+wcslen(beg)+1)*sizeof(*buff));
wcsncpy(buff,ref._path,partln);
wcscpy(buff+partln,beg);
SetDrive(0);
SetDirectory(buff);
return true;
}
int WPathname::IsNetworkPath() const
{
if (wcsncmp(_path,L"\\\\",2)==0) //sitova cesta
{
const wchar_t *p=_path+2;
const wchar_t *c=wcschr(p,'\\');
if (c) return c-_path;
}
return 0;
}
void WPathname::SetServerName(const wchar_t *server)
{
if (HasDrive()) SetDrive(0);
else
{
int np=IsNetworkPath();
_path=_path.Right(np);
}
_path=WSC("\\\\")+WString(server)+WSC("\\");
RebuildPath();
}
void WPathname::SetNull()
{
_fullpath=_path=_filetitle=_extension=0;
}
bool WPathname::GetPartFromPath(const wchar_t *path, int partnum, wchar_t *buff, int bufsize, int mode)
{
const wchar_t *scan=path;
while (*scan=='\\') scan++;
while (partnum && *scan)
{
while (*scan!='\\' && *scan) scan++;
while (*scan=='\\') scan++;
partnum--;
}
if (*scan==0)
{
buff[0]=0;
return false;
}
int pt=0;
if (mode==-1)
{
pt=scan-path;
if (pt>bufsize)
{
buff[0]=0;
return true;
}
else
memcpy(buff,path,pt);
}
bool nlast=false;
while (*scan && (mode==1 || !nlast) && pt<bufsize)
{
buff[pt]=*scan;
pt++;
scan++;
if (*scan=='\\') nlast=true;
}
if (pt==bufsize)
{
buff[0]=0;
return true;
}
buff[pt]=0;
return nlast;
}

View file

@ -0,0 +1,400 @@
// WPathname.h: interface for the WPathname class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WPathname_H__158F59D5_B422_4FA6_86AC_10B5EC48C81B__INCLUDED_)
#define AFX_WPathname_H__158F59D5_B422_4FA6_86AC_10B5EC48C81B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "WString.h"
#ifndef ASSERT
#ifdef _DEBUG
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif
#endif
#define WPathnameCompare(op) bool operator op (const WPathname &other) const \
{if (IsNull() || other.IsNull()) return false;else return wcsicmp(_fullpath,other._fullpath) op 0;}\
bool operator op (const wchar_t *other) const \
{ASSERT(!other || other[0]!=0);\
if (IsNull() || other==NULL) return false;else return wcsicmp(_fullpath,other) op 0;}
/** class WPathname simplifying manipulation with WPathnames, filenames, general paths, and
also supports convert from absolute path to relative respectively */
class WPathname
{
///object value and data
/**The implementation of WPathname creates only one buffer for all variables. It can
increase speed by effective memory use. Strings are stored one after another separated
by zero byte. Evry time any string changed, implementation recalculate buffer usage, and
decide, whether it should resize buffer or not.
_fullpath also points to string contain full path with filename,
it is dominant value of the class
*/
WString _fullpath;
WString _path; ///<current path with drive
WString _filetitle; ///<file title without extension
WString _extension; ///<file extension
public:
///Construct WPathname class.
/** If name is not provided, current path is used, and as filename, WPathname suppl wildcards
*.* . That is useful, for searching in directory.<br>
If name is provided, WPathname will expand it into full name with drive and folder name.
@param name optional argument to inicialize object
*/
WPathname(const wchar_t *name=NULL);
WPathname(const WString &name);
///Construct WPathname class
/**
@param relpath Relative path or uncomplette path or single filename with extension.
WPathname will expand this WPathname into full using absolute path provided by the second
argument.
@param abspath Absolute path used as reference to folder - the origin of relative path
provided in the first argument.
*/
WPathname(const wchar_t *relpath, const WPathname &abspath);
///Construct WPathname as copy of another WPathname
WPathname(const WPathname &other);
///Function returns the current drive letter.
/** Before usage, ensure, that current WPathname contain drive.
In network path drive letter is missing.
In this case, result is undefined. To ensure, use HasDrive function
@return the drive letter of current path.
*/
wchar_t GetDrive() const
{
if (IsNull()) return 0;
return _path[0];
}
///Static function determines, if argument contain a drive information.
/**
@param dir directory to inspect
@return true, if directory contain drive.<p>
This function is independed, it don't need any WPathname variable declared.
*/
static bool HasDrive(const wchar_t *dir)
{return (dir[0]>='A' && dir[0]<='Z' || dir[0]>='a' && dir[0]<='z') && dir[1]==':';}
///Function determines, if current WPathname contain a drive information
/**
@return true, if current WPathname contain a drive information
*/
bool HasDrive() const
{
if (IsNull()) return false;
return HasDrive(_path);
}
///Function returns current folder name
/**
if current folder name contain drive, only folder name is returned (without drive).
In other cases (relative or network drives) returns full path.
@return folder name or full path. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetDirectory() const
{
if (HasDrive()) return _path.GetString()+3;
else return _path.GetString()+IsNetworkPath();
}
const wchar_t *GetDirectoryWithDrive() const
{
return _path;
}
///Function returns current filename with extension
/**
@return current filename with extension. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetFilename() const
{
if (IsNull()) return NULL;
const wchar_t *blk=wcsrchr(_fullpath,'\\');
if (blk) blk=blk+1;else blk=_fullpath;
return blk;
}
///Function returns current extension (with starting dot)
/**
@return current extension. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetExtension() const
{return _extension;}
///Function returns current filename without extension (without dot)
/**
@return current filename without extension (without dot). Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetTitle() const
{return _filetitle;}
///Function changes current drive.
/**If object contain WPathname with drive, then current drive is changed and function returns.
If object contain network path, then computer name is changed to the drive name.
If object contain relative path, then whole path is replaced by path on root on drive.
@param dr new drive letter. This parameter can be set to zero. It means, that current
driver is deleted, and path is converted to relative path from root. Note: Zero c
cannot be used with network paths and relative paths, and finnaly has no effect to the object
*/
void SetDrive(wchar_t dr);
///Sets new directory for object
/** if object contain a drive letter and argument dir doesn't, then current drive is remain
and only directory part is replaced. If current path is network path or relative path,
then whole path is replaced by new one.
If argument dir contain drive letter, then whole path is replaced too.
@param dir contain new WPathname. Backslash should be the last wchar_tacter in string
*/
void SetDirectory(const wchar_t *dir);
///Sets new filename for object.
/**
If filename contain dot, function assumes, that filename is provided with extension.
Otherwise, current extension remains untouched.
@param filename new filename for object
*/
void SetFilename(const wchar_t *filename);
///Sets new extension for object.
/**
If ext doesn't starting with dot, function adds it.
@param ext new extension for object
*/
void SetExtension(const wchar_t *ext);
///Sets new file title
/** Function changes file title, extension remains untouched.
if title contains extension (dot inside its name), this extension doesn't change
current extension. For example, if current extension is ".cpp" and filetitle contain
"source.h", then result is "source.h.cpp"
@param title a new title for object.
*/
void SetFileTitle(const wchar_t *title);
///Function returns full WPathname.
/**
@return current WPathname. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetFullPath() const
{return _fullpath;}
///Sets WPathname
/** Function has same effect as constructor. But it can be used
anytime during object lifetime. It simply replaces current WPathname with newer. WPathname
in argument is expanded to full WPathname, current directory is used as reference.
@param WPathname new WPathname
*/
void SetPathname(const wchar_t *pathname);
void SetPathname(const WString &pathname);
WPathname& operator=(const wchar_t *other)
{SetPathname(other);return *this;}
WPathname& operator=(const WString &other)
{SetPathname(other);return *this;}
WPathname& operator=(const WPathname& other)
{
_fullpath=other._fullpath;
_path=other._path;
_filetitle=other._filetitle;
_extension=other._extension;
return *this;
}
///converts object to string
operator const wchar_t *() const
{return GetFullPath();}
///Static function to help getting filename from WPathname
/** Function finds last backslash / and return pointer to first wchar_tacter after it.
Pointer stays valid until original path is destroyed or until original path is changed
@param path WPathname to inspect as string
@return pointer to filename
*/
static const wchar_t *GetNameFromPath(const wchar_t *path);
///Static function to help getting extension from WPathname
/** Function finds last dot '.' in filename return pointer to it (extension with dot).
Pointer stays valid until original path is destroyed or until original path is changed
@param path WPathname to inspect as string
@return pointer to extension
*/
static const wchar_t *GetExtensionFromPath(const wchar_t *path);
///Function sets server name for network path
/** If current path is network path, then changes server name to newer. Otherwise
it remove drive letter, and insert server name before remain path
@param server server name without slashes
*/
void SetServerName(const wchar_t *server);
///Function inspects current path and returns, whether contain server name
/**@return zero, if current path is not valid network path. Nonzero if path contain
server name. Then value returned count wchar_tacters containing server name with precedent
slashes.
*/
int IsNetworkPath() const;
///Function converts current relative path into absolute path
/**
If current path is not relative, function do nothing.
@param ref reference to path, against which path is relative.
@return true if path has been converted, or false, if conversion is impossible
*/
bool RelativeToFull(const WPathname &ref);
///Function converts current absolute path into relative path
/**
If current path is not relative, function do nothing. Both paths must be on the same
drive or network computer.
@param ref reference to path, against which path should be relative.
@return true if path has been converted, or false, if conversion is impossible
*/
bool FullToRelative(const WPathname &relativeto);
WPathname& operator+=(const wchar_t *relativePath)
{*this=WPathname(relativePath,*this);return *this;}
WPathname operator+(const wchar_t *relativePath)
{WPathname out(relativePath,*this);return out;}
bool IsNull() const {return _fullpath.GetLength()==0;}
void SetNull();
WPathnameCompare(<)
WPathnameCompare(>)
WPathnameCompare(==)
WPathnameCompare(>=)
WPathnameCompare(<=)
WPathnameCompare(!=)
///Function gets part of WPathname
/**
@param path subject of examine
@param partnum zero-base index of part of WPathname. Index 0 mostly contain drive or server, in case of
relative path, there is the name of the first folder or dots.
@param buff buffer for store result
@param bufsize count wchar_tacters in buffer;
@param mode mode=0, gets only name of part.
mode=1, get current part and remain parts of path.
mode=-1, gets all parts till current
@return Function returns true, if it was succesful, and it was not last part. Function returns
false, if it was succesful, and it was last part. Function returns false and sets buffer empty,
if an error occured. Function returns true and sets buffer empty, if buffer is too small to hold data
*/
static bool GetPartFromPath(const wchar_t *path, int partnum, wchar_t *buff, int bufsize, int mode=0);
///Function gets part of object
/**
@param partnum zero-base index of part of WPathname. Index 0 mostly contain drive or server, in case of
relative path, there is the name of the first folder or dots.
@param buff buffer for store result
@param bufsize count wchar_tacters in buffer;
@param mode mode=0, gets only name of part.
mode=1, get current part and remain parts of path.
mode=-1, gets all parts till current
@return Function returns true, if it was succesful, and it was not last part. Function returns
false, if it was succesful, and it was last part. Function returns false and sets buffer empty,
if an error occured. Function returns true and sets buffer empty, if buffer is too small to hold data
*/
bool GetPart(int partnum, wchar_t *buff, int bufsize,int mode=0) const
{
return GetPartFromPath(this->_fullpath,partnum,buff,bufsize,mode);
}
/// Get Directory With Drive Without Last Back Slash
/** Retrieves into buffer directory with drive and removes last backslash
@param buff buffer that retrieves path
@param size size of buffer
@return true, if success, failed if buffer is too small*/
bool GetDirectoryWithDriveWLBS(wchar_t *buff, size_t size) const;
WString GetDirectoryWithDriveWLBS() const;
/// function checks, if path is valid and returns true, if does.
bool IsPathValid() const;
/// Sets special directory.
/**
@param bSpecCode this value may be operation-system
depend. Windows implementation using CSIDL_XXXX constants, which is described in SHGetSpecialFolderLocation function
description
@return true, if function were successful
*/
bool SetDirectorySpecial(int nSpecCode);
///Sets temporaly directory.
bool SetTempDirectory();
///Guess temporaly file name
/**
@param prefix prefix string for name
@param unique if unique is non-zero, it is used for new temporaly file. If unique is zero, function guess own unique
value.
@return true if function were successful
*/
bool SetTempFile(const wchar_t *prefix=L"tmp", unsigned int unique=NULL);
///Returns path of current executable.
/**It useful, when accessing folder, from when current module has been executed */
static WPathname GetExePath();
///Solves most used conversion from fullpath to path relative to project root
/**
@param full full WPathname with drive
@param projectRoot project root path
@return function returns pointer to full path, where starts relative part. If
fullpath doesn't contain project root path, it returns pointer to full.
@example FullToProjectRoot("x:\\project\\data\\example.txt","x:\\project"); //result is "data\\example.txt"
*/
static const wchar_t *FullToRelativeProjectRoot(const wchar_t *full, const wchar_t *projectRoot);
protected:
///Function only rebuild _fullpath string.
/** It doesn't check space for string! This function is used, when length of path is excepted
the same or smaller, then current.
*/
void RebuildPath();
};
#endif // !defined(AFX_WPathname_H__158F59D5_B422_4FA6_86AC_10B5EC48C81B__INCLUDED_)

View file

@ -0,0 +1,193 @@
// WString.cpp: implementation of the WString class.
//
//////////////////////////////////////////////////////////////////////
#include "WString.h"
#include <windows.h>
#include <stdio.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
WString::WString(const char *sbstring, unsigned int codePage)
{
if (sbstring==NULL || *sbstring==0)
{
_ref=NULL;
}
else
{
size_t reqBuff=MultiByteToWideChar(codePage,0,sbstring,-1,NULL,0);
_ref=WStringMemory::AllocString(NULL,reqBuff);
_ref->AddRef();
wchar_t *str=const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
MultiByteToWideChar(codePage,0,sbstring,-1,str,reqBuff);
}
}
int WString::FormatV(wchar_t *format, va_list lst)
{
size_t curSize=4096;
int written;
do
{
_ref=WStringMemory::AllocString(NULL,curSize);
wchar_t *str=const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
written=_vsnwprintf(str,curSize,format,lst);
if (written<0)
{
curSize*=2;
WStringMemory::FreeProxy(_ref);
}
}
while (written<-1);
_ref->RecalcLength();
_ref->AddRef();
return written;
}
int WString::Format(wchar_t *format, ...)
{
va_list valst;
va_start(valst,format);
return FormatV(format,valst);
}
int WString::ScanStringV(const wchar_t *format, va_list lst) const
{
unsigned long *ptr=(unsigned long *)lst;
return swscanf(GetString(),format,ptr[0],ptr[1],ptr[2],ptr[3],ptr[4],ptr[5],ptr[6],ptr[7],ptr[8],ptr[9],
ptr[10],ptr[11],ptr[12],ptr[13],ptr[14],ptr[15],ptr[16],ptr[17],ptr[18],ptr[19]);
}
int WString::ScanString(const wchar_t *format, ...) const
{
va_list valst;
va_start(valst,format);
return ScanStringV(format,valst);
}
bool WString::ReplaceOnce(const WString &findWhat,const WString &replaceWith)
{
int pos=Find(findWhat);
if (pos==-1) return false;
(*this)=Left(pos)+replaceWith+Right(pos+replaceWith.GetLength());
return true;
}
bool WString::ReplaceAll(const WString &findWhat,const WString &replaceWith)
{
WString process=*this;
WString result;
int pos;
bool processed=false;
while ((pos=process.Find(findWhat))!=-1)
{
result=result+process.Left(pos)+replaceWith;
process=process.Right(pos+findWhat.GetLength());
processed=true;
}
*this=result+process;
return processed;
}
WString WString::TrimLeft() const
{
return TrimLeft(L" \r\n\t");
}
WString WString::TrimRight() const
{
return TrimRight(L" \r\n\t");
}
WString WString::TrimLeft(wchar_t *trimChars) const
{
const wchar_t *proStr=GetString();
int p=0;
while (proStr[p] && wcschr(trimChars,proStr[p]!=NULL)) p++;
return Right(p);
}
WString WString::TrimRight(wchar_t *trimChars) const
{
const wchar_t *proStr=GetString();
int p=GetLength()-1;
while (p>=0 && wcschr(trimChars,proStr[p]!=NULL)) p--;
return Left(p+1);
}
WString WString::Upper() const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,WStringProxy::EfUpper)));
}
WString WString::Lower() const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,WStringProxy::EfLower)));
}
WString WString::Reverse() const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,WStringProxy::EfReverse)));
}
WString WString::Effect(IWStringEffect *effect) const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,effect)));
}
void WString::SetUTF7(const char *utf7)
{
*this=WString(utf7,CP_UTF7);
}
void WString::SetUTF8(const char *utf8)
{
*this=WString(utf8,CP_UTF8);
}
const char *WString::AsSBString(unsigned int codePage, WString &holder)
{
const wchar_t *str=GetString();
size_t reqsize=WideCharToMultiByte(codePage,0,str,-1,NULL,0,NULL,NULL);
WStringProxy *holderProxy=WStringMemory::AllocString(NULL,reqsize/2); //reqsize/2+(2 bytes)
char *mbstr=reinterpret_cast<char *>(const_cast<wchar_t *>(holderProxy->GetStringFromMemBlock()));
WideCharToMultiByte(codePage,0,str,-1,mbstr,reqsize,NULL,NULL);
holder=WString(holderProxy);
return mbstr;
}
const char *WString::AsUTF7(WString &holder)
{
return AsSBString(CP_UTF7,holder);
}
const char *WString::AsUTF8(WString &holder)
{
return AsSBString(CP_UTF8,holder);
}
void WString::ReadFromStream(size_t (*streamReader)(wchar_t *buffer, size_t bufferLen, void *context),void *context)
{
_ref->Release();
_ref=NULL;
wchar_t buff[256];
size_t rd;
while ((rd=streamReader(buff,sizeof(buff)/sizeof(wchar_t),context))!=0)
{
*this=*this+WString(buff,rd);
}
}
const WString WStringConst(const wchar_t *text)
{
return WString(WStringMemory::AllocProxy(WStringProxy(text)));
}

View file

@ -0,0 +1,496 @@
// WString.h: interface for the WString class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WSTRING_H__481164FB_3BB7_4824_B0E3_8B371F0AAF3A__INCLUDED_)
#define AFX_WSTRING_H__481164FB_3BB7_4824_B0E3_8B371F0AAF3A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "WStringProxy.h"
#include <stdlib.h>
class WString
{
mutable WStringProxy *_ref;
public:
///constructs empty string
WString():_ref(0) {}
///constructs string.
explicit WString(const wchar_t *string):_ref(string==NULL?NULL:WStringMemory::AllocString(string,0)) {_ref->AddRef();};
///constructs string from wide-char array with specified length
WString(const wchar_t *string, size_t sz):_ref(WStringMemory::AllocString(string,sz)) {_ref->AddRef();};
///copy constructor
/**constructor doesn't copy the string, only reference.
String is shared until it is changed
*/
WString(const WString &other):_ref(other._ref) {_ref->AddRef();}
///constructs string from multi-byte string. codePage specified code page of string
WString(const char *sbstring, unsigned int codePage);
///constructs string from string-proxy. Used internally with WStringMemory::AllocXXX functions
WString(WStringProxy *proxy):_ref(proxy) {_ref->AddRef();}
///assignment operator
/** assignment operator doesn't copy the string only reference.
String is shared until it is changed */
WString &operator=(const WString &other)
{other._ref->AddRef();_ref->Release();_ref=other._ref;return *this;}
///Destructor - releases reference
~WString() {_ref->Release();}
///function converts instance of WString to wchar_t pointer
/**
Function will perform RenderString, if it is needed.
*/
const wchar_t *GetString() const
{
if (_ref==NULL) return L"";
WStringProxy *str=_ref->RenderString();
if (_ref!=str)
{
str->AddRef();_ref->Release();_ref=str;
}
return _ref->GetStringFromMemBlock();
}
///operator can convert WString to wchar_t pointer anytime
operator const wchar_t *() const {return GetString();}
///function returns count of characters in string
/** function doesn't need to render string, so it can be called anytime
without loosing the benefit of "pseudo-strings" boosting */
size_t GetLength() const
{
if (_ref) return _ref->GetLength();
else return 0;
}
///function creates string as sum of this and another string
/** function creates "pseudo-string" that represents sum of two string.
pseudo-string is rendered to "real-string" automatically, when it is needed */
WString operator+(const WString other) const
{
if (_ref==NULL) return other;
if (other._ref==NULL) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,other._ref)));
}
WString &operator+=(const WString other)
{
*this=*this+other;
return *this;
}
///function creates string as substring of another string
/** function creates "pseudo-string" that represents substring of anothers string.
Pseudo-string is rendered to "real-string" automatically, when it is needed */
WString Mid(size_t begin, size_t len) const
{
if (begin==0) return Left(len);
if (_ref==NULL || begin>GetLength()) return WString();
if (begin+len>GetLength()) return Right(begin);
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,begin,len)));
}
WString Left(size_t len) const
{
if (_ref==NULL) return WString();
if (len>=GetLength()) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,0,len)));
}
WString Right(size_t begin) const
{
if (_ref==NULL || begin>GetLength()) return WString();
if (begin==0) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,begin,GetLength()-begin)));
}
WString RightR(size_t count) const
{
if (_ref==NULL || count==0) return WString();
if (count>=GetLength()) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,GetLength()-count,count)));
}
WString Delete(size_t begin, size_t count) const
{
if (_ref==NULL) return WString();
if (begin==0) return Right(count);
if (begin+count>=GetLength()) return Left(begin);
return WString(WStringMemory::AllocProxy(WStringProxy(Left(begin)._ref,Right(begin+count)._ref)));
}
WString Insert(const WString &what, size_t index) const
{
if (_ref==NULL) return what;
if (index==0) return what+*this;
if (index>=GetLength()) return *this+what;
return Left(index)+what+Right(index);
}
/// function allows to access any char in string
wchar_t operator[](int index) const
{
assert(index<=(int)GetLength() && index>=0);
return GetString()[index];
}
/// functions allows lock string for accesing it directly.
/** Function returns pointer to buffer which holds string.
Buffer size is equal to string length plus terminating zero.
Application can modify content of buffer.
If string is shared with another WString object, LockBuffer
creates copy of string
Do not forger to call UnlockBuffer, when you finish modifiing the content
*/
wchar_t *LockBuffer()
{
if (_ref==NULL) return NULL;
GetString();
WStringMemory::LockProxy(_ref);
if (_ref->IsShared())
{
WStringMemory::UnlockProxy(_ref);
_ref->Release();
_ref=WStringMemory::AllocString(_ref->GetStringFromMemBlock(),0);
_ref->AddRef();
WStringMemory::LockProxy(_ref);
}
return const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
}
/// Function creates buffer for string and returns its address
/** Application can use buffer in functions, that cannot work with
WString objects. Size of buffer is specified by sz value, and it is in characters.
Application must call UnlockBuffer after writes all data into buffer.
NOTE: Prevoius content of string is lost.
NOTE: sz specifies buffer size without terminating zero character
*/
wchar_t *CreateBuffer(size_t sz)
{
_ref->Release();
_ref=WStringMemory::AllocString(NULL,sz);
_ref->AddRef();
WStringMemory::LockProxy(_ref);
return const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
}
/// Function creates buffer, and copies string into it.
/** Parameter sz specifies size of new buffer in characters
When sz is smaller then size of string, string is truncated
When sz is larger then size of string, string is copied unchanged,
but extra characters can be appended.
NOTE: sz specifies buffer size without terminating zero character
*/
wchar_t *CreateBufferCopy(size_t sz)
{
WString save=*this;
wchar_t *wbuff=CreateBuffer(sz);
int minsz=__min(sz,save.GetLength());
wcsncpy(wbuff,save.GetString(),minsz);
return wbuff;
}
/// Function unlocks internal buffer
/** parameter sz specifies final lenght of string in buffer. Default
value -1 forces function calc size by own
*/
void UnlockBuffer(int sz=-1)
{
if (_ref==NULL) return;
wchar_t *wbuff=const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
if (sz<0) sz=wcslen(wbuff);
else wbuff[sz]=0;
if (sz!=(signed)_ref->GetLength())
{
_ref->RecalcLength();
WStringMemory::UnlockProxy(_ref);
}
}
class WStringAtCharHelper
{
WString &_str;
size_t _index;
public:
WStringAtCharHelper(WString &str,size_t index):_str(str),_index(index) {}
WString &operator=(wchar_t z)
{
wchar_t *buff=_str.LockBuffer();
assert(buff && _index<_str.GetLength());
buff[_index]=z;
_str.UnlockBuffer();
return _str;
}
operator wchar_t()
{
assert(_index<_str.GetLength());
return ((const wchar_t *)_str)[_index];
}
};
/// Function will return helper object, which can access single character in string
/**
Using array operator is slower than accessing characters by LockBuffer function
*/
WStringAtCharHelper operator[](int index)
{
return WStringAtCharHelper(*this,index);
}
int Find(wchar_t z,size_t from=0) const
{
if (from>=GetLength()) return -1;
const wchar_t *res=wcschr(GetString()+from,z);
if (res) return res-GetString();
else return -1;
}
int FindLast(wchar_t z) const
{
const wchar_t *res=wcsrchr(GetString(),z);
if (res) return res-GetString();
else return -1;
}
int Find(const wchar_t *z,size_t from=0) const
{
if (z==NULL) return -1;
if (from>=GetLength()) return -1;
const wchar_t *res=wcsstr(GetString()+from,z);
if (res) return res-GetString();
else return -1;
}
int FormatV(wchar_t *format, va_list lst);
int Format(wchar_t *format, ...);
///Scans string for format
/** function is limited, item count is limited up to 20 items */
int ScanStringV(const wchar_t *format, va_list lst) const;
///Scans string for format
/** function is limited, item count is limited up to 20 items */
int ScanString(const wchar_t *format, ...) const;
bool ReplaceOnce(const WString &findWhat,const WString &replaceWith);
bool ReplaceAll(const WString &findWhat,const WString &replaceWith);
WString TrimLeft() const;
WString TrimRight() const;
WString TrimLeft(wchar_t *trimChars) const;
WString TrimRight(wchar_t *trimChars) const;
///Function splits string into two
/** Left part of string is returned.
Right part of string is leaved in object
@param splitPos split position.
@return if splitPos==0, function returns empty string. if splitPos>=length, function
moves string from object to result*/
WString Split(size_t splitPos)
{
WString result=Left(splitPos);
*this=Right(splitPos);
return result;
}
bool IsEmpty() const {return _ref==NULL;}
void Empty() const {_ref->Release();_ref=NULL;}
int Compare(const wchar_t *other) const
{
return wcscmp(*this,other);
}
bool operator>(const WString &other) const {return Compare(other)>0;}
bool operator<(const WString &other) const {return Compare(other)<0;}
bool operator>=(const WString &other) const {return Compare(other)>=0;}
bool operator<=(const WString &other) const {return Compare(other)<=0;}
bool operator!=(const WString &other) const {return Compare(other)<=0;}
bool operator==(const WString &other) const {return Compare(other)<=0;}
WString Upper() const;
WString Lower() const;
WString Reverse() const;
///Applies user effect on string
/** pointer should be static allocated object, or must be valid during lifetime of resulting string */
WString Effect(IWStringEffect *effect) const;
void SetUTF7(const char *utf7);
void SetUTF8(const char *utf8);
///Function converts string to SingleByte string
/**
@param codePage Platform depends code page of result
@param holder Object that holds result. Result pointer is valid during lifetime of holder. Once holder
released, pointer is invalidated. You can get resulting pointer anytime from holder reintepreting
wchar_t to char
@result pointer to string
*/
const char *AsSBString(unsigned int codePage, WString &holder);
///Returns multibyte string in UTF7 codepage
/**See AsSBString description*/
const char *AsUTF7(WString &holder);
///Returns multibyte string in UTF7 codepage
/**See AsSBString description*/
const char *AsUTF8(WString &holder);
///Function reads string from stream
/**
Function calls streamReader repeatly until function returns zero. In each call, streamReader returns
number of characters, that has been readed.
@param sreamReader pointer to function which provides reading from a stream
@param context user defined context pointer (most in cases, pointer to stream is passed)
@param buffer space allocated for data readed from stream
@param bufferLen maximum count of characters can be written to buffer
@return streamReader returns number of characters, that has been written to buffer. Function must return zero
to stop reading
*/
void ReadFromStream(size_t (*streamReader)(wchar_t *buffer, size_t bufferLen, void *context),void *context);
WString operator() (int from) const {return from<0?RightR(-from):Right(from);}
WString operator() (int from, int to) const
{
if (from>=0)
return to<0?Mid(from,-to):Mid(from,to-from);
else
return to<0?Mid(GetLength()+from,-to):Mid(GetLength()+from,GetLength()-from-to);
}
///Enables global string sharing.
/** Function Share allows share strings that contains same text. It can reduce memory
usage. Function is useful when there is many objects that contains string with same text.
Basically, two strings is shared, if one string is created as copy of another string. Strings
is sharing they content, until one of them is modified.
Calling Share function, string is registered for global sharing. If string with same content is already
registered, then content of current string is released, and string is shared.
To successfully share two strings, both strings must call Share() function. Sharing is provided until one
of strings is modified. After modifications are done, Share function of modified string must be called again.
Remember: Global sharing can reduce amount of memory, if there are multiple strings that containging
the same content. But sharing of each unique string takes small piece of memory to store sharing
informations.
To share string automatically, use WSharedString class
WSC strings cannot be shared!
*/
void Share() const
{
WStringProxy *curref=_ref;
GetString();
_ref=WStringMemory::ShareString(curref);
_ref->AddRef();
curref->Release();
}
///Disables global string sharing
/** Function unregisters string from global sharing database. If string is shared, function doesn't break
it. But all strings that currently sharing content will not be shared with newly created strings.
*/
void Unshare()
{
WStringMemory::UnshareString(_ref);
}
};
///Function will create constant WString
/** function will not copy content of string. Only creates reference to string
Using WStringConst is faster for strings in code
@exmple result=a+WStringConst(L"text")+b;
*/
const WString WStringConst(const wchar_t *text);
///Macro to easy convert incode string to WString
/**
function also marks text wide.
@example WString text=WSC("Hello world");
*/
#define WSC(x) WStringConst(L##x)
///Macro to easy convert any wchar_t buffer to constant WString
/**
IMPORTANT NOTE!: Buffer must exists until string is rendered.
If you are using WSCB in function, don't forget call GetString before function exits
If you are excepting additional string operations outside function, using standard
WString conversion can be more effecient.
*/
#define WSCB(x) WStringConst(x)
class WSharedString: public WString
{
public:
WSharedString() {}
///constructs string.
explicit WSharedString(const wchar_t *string):WString(string) {Share();}
///constructs string from wide-char array with specified length
WSharedString(const wchar_t *string, size_t sz):WString(string,sz) {Share();};
///copy constructor
/**constructor doesn't copy the string, only reference.
String is shared until it is changed
*/
WSharedString(const WSharedString &other):WString(other) {}
WSharedString(const WString &other):WString(other) {Share();}
///constructs string from multi-byte string. codePage specified code page of string
WSharedString(const char *sbstring, unsigned int codePage):WString(sbstring,codePage) {Share();}
///assignment operator
/** assignment operator doesn't copy the string only reference.
String is shared until it is changed */
WSharedString &operator=(const WString &other)
{WString::operator =(other);Share();return *this;}
const wchar_t *GetString() const
{
const wchar_t *res=WString::GetString();
Share();
return res;
}
operator const wchar_t *() const {return GetString();}
wchar_t operator[](int index) const
{
assert(index<=(int)GetLength() && index>=0);
return GetString()[index];
}
void UnlockBuffer(int sz=-1)
{
WString::UnlockBuffer(sz);
Share();
}
};
#endif // !defined(AFX_WSTRING_H__481164FB_3BB7_4824_B0E3_8B371F0AAF3A__INCLUDED_)

View file

@ -0,0 +1,397 @@
// WStringMemorySingleThread.cpp: implementation of the WStringMemory class.
//
//////////////////////////////////////////////////////////////////////
#include <malloc.h>
#include <windows.h>
#include "WStringMemory.h"
#include "WStringProxy.h"
#include <assert.h>
#include <stdio.h>
#include <projects/btree/btree.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifdef _MT //multithreading
#define WSTRING_MT
#endif
#ifdef WSTRING_MT //multithreading
struct WStringMTLock
{
WStringProxy *_lockProxy;
LONG _recursionCount;
DWORD _owner;
HANDLE _event;
WStringMTLock(WStringProxy *x):_lockProxy(x) {}
WStringMTLock():_lockProxy(NULL) {}
bool operator==(const WStringMTLock &other) const {return _lockProxy==other._lockProxy;}
bool operator!=(const WStringMTLock &other) const {return _lockProxy!=other._lockProxy;}
bool operator>=(const WStringMTLock &other) const {return _lockProxy>=other._lockProxy;}
bool operator<=(const WStringMTLock &other) const {return _lockProxy<=other._lockProxy;}
bool operator>(const WStringMTLock &other) const {return _lockProxy>other._lockProxy;}
bool operator<(const WStringMTLock &other) const {return _lockProxy<other._lockProxy;}
int operator=(int zero) {_lockProxy=NULL;return zero;}
};
static CRITICAL_SECTION GLocker={{0},-1,0,0,0,0};
static HANDLE GLockProxy=NULL; //event object to notify waiters that somebody unlocks;
static BTree<WStringMTLock> *GLockDB=NULL; //Lock proxy database
static void exitMT()
{
DeleteCriticalSection(&GLocker);
}
static void OnStartup()
{
InitializeCriticalSection(&GLocker);
atexit(exitMT);
}
#define ON_STARTUP_PRIORITY_NORMAL OnStartup
#include <Es/Common/Startup.hpp>
#endif
#define WS_MAXFREELISTS 32
#define WS_FREELISTSTEP 32
#define WS_TOTALMAXFREEKBYTES 256
#define WS_MAXIMUMFASTALLOC (WS_MAXFREELISTS*WS_FREELISTSTEP)
#define WS_MAXFREEBYTES PerSlotMaxAlloc
static size_t PerSlotMaxAlloc=(WS_TOTALMAXFREEKBYTES*1024/WS_MAXFREELISTS);
static WStringProxy *FreeList=NULL;
static void **StringFreeList[WS_MAXFREELISTS];
static size_t StringFreeBytes[WS_MAXFREELISTS];
static bool InitManager=true;
static void InitManagerPointers()
{
memset(StringFreeList,0,sizeof(StringFreeList));
memset(StringFreeBytes,0,sizeof(StringFreeBytes));
InitManager=false;
}
static void *AllocStringBlock(size_t sz)
{
if (InitManager) InitManagerPointers();
if (sz>WS_MAXIMUMFASTALLOC) return malloc(sz);
int pos=(sz+WS_FREELISTSTEP-1)/WS_FREELISTSTEP;
void **nxt=StringFreeList[pos];
if (nxt==0)
{
printf("malloc %d\n",pos*WS_FREELISTSTEP);
return malloc(pos*WS_FREELISTSTEP);
}
printf("fast_alloc %d\n",pos*WS_FREELISTSTEP);
StringFreeList[pos]=(void **)(*nxt);
StringFreeBytes[pos]-=_msize(nxt);
return nxt;
}
static void DeallocStringBlock(void *ptr)
{
size_t sz=_msize(ptr);
if (sz>WS_MAXIMUMFASTALLOC) {free(ptr);return;}
int pos=(sz+WS_FREELISTSTEP-1)/WS_FREELISTSTEP;
if (sz+StringFreeBytes[pos]>WS_MAXFREEBYTES)
{
printf("free %d\n",sz);
free(ptr);return;
}
void **proxy=(void **)ptr;
*proxy=(void *)StringFreeList[pos];
StringFreeList[pos]=proxy;
StringFreeBytes[pos]+=sz;
printf("fast_free %d\n",sz);
}
static inline void *operator new(size_t alloc,size_t sz)
{
return AllocStringBlock(sz+alloc);
}
static inline void operator delete(void *p,size_t alloc)
{
DeallocStringBlock(p);
}
static inline void *operator new(size_t sz,void *ptr)
{
return ptr;
}
static inline void operator delete(void *ptr,void *p)
{
}
WStringProxy * WStringMemory::AllocString(const wchar_t *text, size_t size)
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
assert(size!=0 || text!=0);
if (size==0) size=wcslen(text);
WStringProxy *proxy=new((size+1)*sizeof(wchar_t)) WStringProxy(size,0,0);
wchar_t *alloctext=const_cast<wchar_t *>(proxy->GetStringFromMemBlock());
if (text) wcsncpy(alloctext,text,size);
alloctext[size]=0;
if (proxy->_redirect==0)
{
proxy->_redirect=alloctext;
proxy->_blockData2=1;
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return proxy;
}
WStringProxy * WStringMemory::AllocProxy(const WStringProxy &templateProxy)
{
WStringProxy * res;
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
if (FreeList==NULL) res=new WStringProxy(templateProxy);
else
{
WStringProxy *alloc=FreeList;
FreeList=alloc->_baseString;
res=new((void *)alloc) WStringProxy(templateProxy);
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return res;
}
void WStringMemory::FreeProxy(WStringProxy *proxy)
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
if (proxy->_operation==proxy->OpMemBlck && !(proxy->_blockData2==0 && proxy->_redirect!=NULL))
{
if (proxy->_blockData2==2) UnshareString(proxy);
DeallocStringBlock(proxy);
}
else
{
proxy->~WStringProxy();
proxy->_baseString=FreeList;
FreeList=proxy;
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
}
#ifdef WSTRING_MT
void WStringMemory::LockProxy( WStringProxy *proxy)
{
nextTry:
EnterCriticalSection(&GLocker);
WStringMTLock srch(proxy),*found;
if (GLockDB==NULL) GLockDB=new BTree<WStringMTLock>(16);
found=GLockDB->Find(srch);
if (found==NULL)
{
srch._event=NULL;
srch._owner=GetCurrentThreadId();
srch._recursionCount=1;
GLockDB->Add(srch);
}
else
{
if (found->_owner!=GetCurrentThreadId())
{
HANDLE w=found->_event;
if (w==0) {w=found->_event=CreateEvent(NULL,TRUE,FALSE,NULL);}
LeaveCriticalSection(&GLocker); //leave section
WaitForSingleObject(w,INFINITE);
goto nextTry;
}
else
{
found->_recursionCount++;
}
}
LeaveCriticalSection(&GLocker); //leave section
}
void WStringMemory::UnlockProxy( WStringProxy *proxy)
{
EnterCriticalSection(&GLocker);
WStringMTLock srch(proxy),*found;
found=GLockDB->Find(srch);
if (found)
{
if (--found->_recursionCount==0)
{
if (found->_event!=NULL)
{
SetEvent(found->_event);
CloseHandle(found->_event);
}
GLockDB->Remove(*found);
}
}
LeaveCriticalSection(&GLocker);
}
void WStringMemory::AddRefProxy(WStringProxy *proxy)
{
InterlockedIncrement(reinterpret_cast<LONG *>(&proxy->_refCount));
}
bool WStringMemory::ReleaseRefProxy(WStringProxy *proxy)
{
LONG res=InterlockedDecrement(reinterpret_cast<LONG *>(&proxy->_refCount));
if (res<0) res=InterlockedIncrement(reinterpret_cast<LONG *>(&proxy->_refCount));
return res==0;
}
#else
void WStringMemory::LockProxy( WStringProxy *proxy)
{
//not needed in single thread environment
}
void WStringMemory::UnlockProxy( WStringProxy *proxy)
{
//not needed in single thread environment
}
void WStringMemory::AddRefProxy(WStringProxy *proxy)
{
//no special handling in single thread environment
++proxy->_refCount;
}
bool WStringMemory::ReleaseRefProxy(WStringProxy *proxy)
{
//no special handling in single thread environment
if (proxy->_refCount) --proxy->_refCount;
return proxy->_refCount==0;
}
#endif
void WStringMemory::FreeExtra()
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
while (FreeList)
{
void *proxy=FreeList;
FreeList=FreeList->_baseString;
free(proxy);
}
for (int i=0;i<WS_MAXFREELISTS;i++)
{
while (StringFreeList[i])
{
void **proxy=StringFreeList[i];
StringFreeList[i]=(void **)(*proxy);
free(proxy);
}
StringFreeBytes[i]=0;
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
}
size_t WStringMemory::GetStatistics(size_t *details)
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
size_t sum=0;
for (int i=0;i<WS_MAXFREELISTS;i++)
{
sum+=StringFreeBytes[i];
if (details) details[i]=StringFreeBytes[i];
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return sum;
}
struct ShareDBItem
{
WStringProxy *_str;
ShareDBItem(WStringProxy *str=NULL):_str(str) {}
int Compare(const ShareDBItem& other) const
{
if (_str==NULL) return other._str!=NULL?1:0;
if (other._str==NULL) return -1;
return wcscmp(_str->_redirect,other._str->_redirect);
}
bool operator==(const ShareDBItem& other) const {return Compare(other)==0;}
bool operator>=(const ShareDBItem& other) const {return Compare(other)>=0;}
bool operator<=(const ShareDBItem& other) const {return Compare(other)<=0;}
bool operator!=(const ShareDBItem& other) const {return Compare(other)!=0;}
bool operator>(const ShareDBItem& other) const {return Compare(other)>0;}
bool operator<(const ShareDBItem& other) const {return Compare(other)<0;}
};
static BTree<ShareDBItem> *GDB=NULL;
WStringProxy *WStringMemory::ShareString(WStringProxy *proxy)
{
if (proxy->_operation!=WStringProxy::OpMemBlck || proxy->_blockData2==0 || proxy->_blockData2==2) return proxy;
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
if (GDB==NULL) GDB=new BTree<ShareDBItem>;
proxy->_blockData2=2; //block is subject of sharing
proxy->_redirect=proxy->GetStringFromMemBlock(); //setup pointer to string
ShareDBItem *found=GDB->Find(ShareDBItem(proxy));
if (found) {proxy->_blockData2=1;proxy=found->_str;}
else GDB->Add(ShareDBItem(proxy));
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return proxy;
}
void WStringMemory::UnshareString(WStringProxy *proxy)
{
if (proxy->_operation!=WStringProxy::OpMemBlck || proxy->_blockData2!=2) return;
if (GDB==NULL) return;
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
GDB->Remove(ShareDBItem(proxy));
proxy->_blockData2=1;
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
}

View file

@ -0,0 +1,61 @@
// WStringMemory.h: interface for the WStringMemory class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WSTRINGMEMORY_H__79693029_4788_4099_9A97_92AF310A7AD5__INCLUDED_)
#define AFX_WSTRINGMEMORY_H__79693029_4788_4099_9A97_92AF310A7AD5__INCLUDED_
#include <WCHAR.H>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class WStringProxy;
class WStringMemory
{
public:
static WStringProxy * AllocString(const wchar_t *text, size_t size);
static WStringProxy * AllocProxy(const WStringProxy &templateProxy);
static void FreeProxy(WStringProxy *proxy);
static void LockProxy(WStringProxy *proxy);
static void UnlockProxy(WStringProxy *proxy);
//Releases extra memory leaved for future fast allocations
static void FreeExtra();
//Support addref for proxy - Single- or Multi- thread support
static void AddRefProxy(WStringProxy *proxy);
//Support addref for proxy - Single- or Multi- thread support
//returns true, when counter reached zero
static bool ReleaseRefProxy(WStringProxy *proxy);
///Gets statistics about memory manager
/**
@param details optional pointer to 32 size_t items. Array will be filled
with sizes of each string fastalloc group.
@return function returns total bytes allocated for string fast allocation.
(This number should be below 256KB)
*/
static size_t GetStatistics(size_t *details=NULL);
///Function allows sharing the strings
/** This function is called by WString::Share function
Function mark proxy shared. If string is same as shared,
it returns pointer to proxy with proxy of string that contains
the same text.
Read description of WString::Share for more informations
*/
static WStringProxy *ShareString(WStringProxy *proxy);
///Function disables sharing of the string
static void UnshareString(WStringProxy *proxy);
};
#endif // !defined(AFX_WSTRINGMEMORY_H__79693029_4788_4099_9A97_92AF310A7AD5__INCLUDED_)

View file

@ -0,0 +1,185 @@
// WStringProxy.cpp: implementation of the WStringProxy class.
//
//////////////////////////////////////////////////////////////////////
#include "WStringProxy.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/** Funkce vytvoøí transitivní uzávìr.
to znamená, že zruší všechny zøetìzené redirecty.
*/
WStringProxy *WStringProxy::TransitivniUzaver()
{
if (_operation==OpSubstr && _offset==0 && _stringSize==_baseString->GetLength())
{
WStringProxy *next=_baseString->TransitivniUzaver();
if (next==NULL) return this;
next->AddRef();
_baseString->Release();
_baseString=next;
return next;
}
return NULL;
}
/** Main render procedure
It creates allocates buffer proxy and renders tree into it
Then turns self into redirect proxy a redirect self into newly created string
Rerurns pointer to newly created proxy
*/
WStringProxy *WStringProxy::RenderString()
{
if (_operation==OpMemBlck) return this;
WStringProxy *pp=TransitivniUzaver();
if (pp!=NULL) return pp->_baseString->RenderString();
WStringProxy *newProxy=WStringMemory::AllocString(NULL,_stringSize);
wchar_t *renderPtr=const_cast<wchar_t *>(newProxy->GetStringFromMemBlock());
RenderStringToBuffer(renderPtr);
newProxy->AddRef();
this->~WStringProxy();
_operation=OpSubstr;
_offset=0;
_baseString=newProxy;
return newProxy;
}
/** Function renders simple effect into buffer
Function needs buffer with nul terminated string
*/
void WStringProxy::RenderSimpleEffect(wchar_t *renderPtr)
{
assert(_operation==OpEffect);
switch (_effect)
{
case EfLower: wcslwr(renderPtr);break;
case EfUpper: wcsupr(renderPtr);break;
case EfReverse: wcsrev(renderPtr);break;
}
}
/** Light phase of rendering. Used to render string that is not
created from substring. This part is optimized for concat and user effects
When substring must be rendered, function call RenderStringToBufferSubstr to
render substring.
*/
void WStringProxy::RenderStringToBuffer(wchar_t *renderPtr)
{
WStringMemory::LockProxy(this);
switch (_operation)
{
case OpConcat:
_baseString->RenderStringToBuffer(renderPtr);
_secondString->RenderStringToBuffer(renderPtr+_baseString->GetLength());
break;
case OpSubstr:
{
_baseString->RenderStringToBufferSubstr(renderPtr,_offset,GetLength());
}
break;
case OpMemBlck:
{
const wchar_t *str=GetStringFromMemBlock();
wcsncpy(renderPtr,str,_stringSize);
}
break;
case OpEffect:
{
unsigned long offset=0;
renderPtr[_stringSize]=0; //we can append zero, because right side of string is not yet rendered
//if this is end of string, one extra character for zero is also allocated.
//efect functions can rely on it.
if (_blockData2>=256) offset=_userEffect->PreRenderString(renderPtr,_baseString->GetLength()); //call prerender to prepare begin of buffer
_baseString->RenderStringToBuffer(renderPtr+offset); //render string to rest of buffer
if (_blockData2>=256) _userEffect->RenderString(renderPtr,_baseString->GetLength()); //apply effect to buffer
else RenderSimpleEffect(renderPtr);
}
break;
};
WStringMemory::UnlockProxy(this);
}
/**
Deep phase of rendering. Function can render substrings, or render substring of two
concated strings. Function can also perform partial effect on string. Function cannot
handle partial user effect, so this effects are converted to things strings.
*/
void WStringProxy::RenderStringToBufferSubstr(wchar_t *renderPtr, size_t offset, size_t size)
{
WStringMemory::LockProxy(this);
switch (_operation)
{
case OpConcat:
{
//process substring of concat
//count characters in buffer
size_t rendered;
//when string starts in left string
if (_baseString->GetLength()>offset)
{
//calculate total characters that may be rendered
rendered=_baseString->GetLength()-offset;
//but limit it to request size
if (rendered>size) rendered=size;
//render substring into buffer
_baseString->RenderStringToBufferSubstr(renderPtr,offset,rendered);
}
else
//no character has been rendered
rendered=0;
//there is still characters remained to render. We will take it from second string
if (size-rendered>0)
{
if (offset>_baseString->GetLength()) offset-=_baseString->GetLength();
else offset=0;
_secondString->RenderStringToBufferSubstr(renderPtr+rendered,offset,size-rendered);
}
}
break;
case OpSubstr:
{ //rendering substrings is very easy
offset+=_offset; //add offset of substring
assert(offset+size<=GetLength()); //check length
//render substring
this->RenderStringToBufferSubstr(renderPtr,offset,size);
}
break;
case OpMemBlck:
{
//rendering from memory, final stop in recursion
//Get pointer string
const wchar_t *str=GetStringFromMemBlock();
//copy substring from string into render buffer
wcsncpy(renderPtr,str+offset,size);
}
break;
case OpEffect:
if (_blockData2>=256) //interface cannot handle partial rendering
{
RenderString(); //convert proxy to simple redirect and render it
RenderStringToBufferSubstr(renderPtr,offset,size); //now we are able to cut out part
}
else
{
//all standard effects maps string 1:1
//first get content of substring into buffer
_baseString->RenderStringToBufferSubstr(renderPtr,offset,size);
//we can append zero, because right side of string is not yet rendered
renderPtr[size]=0;
//process effect on target
RenderSimpleEffect(renderPtr);
}
break;
};
WStringMemory::UnlockProxy(this);
}

View file

@ -0,0 +1,232 @@
// WStringProxy.h: interface for the WStringProxy class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WSTRINGPROXY_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_)
#define AFX_WSTRINGPROXY_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "WStringMemory.h"
#include "IWStringEffect.h"
#include <WCHAR.H>
#include <string.h>
#include <assert.h>
#include <malloc.h>
/*
List of proxy types
Memory_Proxy _operation=OpMemBlck
_blockData==0 and _blockData2==0
or
_blockData!=0 and _blockData2!=0
(_redirect - debug pointer)
(_blockData - 1)
Proxy_Const _operation=OpMemBlck
_redirect - pointer to string
_blockData2=0
Proxy_Shared _operation=OpMemBlck
_redirect - pointer to string
_blockData2=2;
Proxy_Immediate _operation=OpMemBlck
_blockData>0xFFFF
_blockData2>0xFFFF
both parameters are used by immediate memory manager
Proxy_Concat _operation=OpConcat
_baseString and _secondString is valid
Proxy_Link _operation=OpSubstr
_baseString is valid
_stringSize==_baseString->_stringSize
_offset==0;
NOTE: Can be used without rendering
Proxy_RightSub _operation=OpSubstr
_baseString is valid
_offset<=_baseString->_stringSize
_stringSize==_baseString->_stringSize-_offset
NOTE: Can be used without rendering
Proxy_SubString _operation=OpSubstr
_baseString is valid
_offset<=_baseString->_stringSize
_stringSize<=_baseString->_stringSize-_offset
Proxy_Effect _operation=OpEffect
_baseString is valid
_stringSize=_baseString->_stringSize
_effect defining effect code < 0xFFFF
Proxy_UserEffect _operation=OpEffect
_baseString is valid
_stringSize=_baseString->_stringSize
_effect>0xFFFF
_userEffect defining pointer to effect interface
*/
class WStringProxy
{
public:
enum Operation
{
OpConcat=0, //proxy contains two links to concat it
OpSubstr=1, //proxy contains link to another proxy and specified substring
OpMemBlck=-2, //proxy contains informations about following string
OpEffect=-1, //proxy describing some efect with string
};
enum Effect
{
EfLower, //effect lower case
EfUpper, //effect upper case
EfReverse, //effect reverse string
};
public:
unsigned long _refCount; //reference count
unsigned long _stringSize:30; //string size in characters (maximum size 1073741823 characters ~ 2147483646 bytes)
Operation _operation:2; //operation with string or proxy type
union
{
WStringProxy *_baseString; //pointer to next proxy referenced by this proxy
unsigned long _blockData; //user defined block data for OpMemBlock proxy type
const wchar_t *_redirect; //used for OpMemBlock, when _blockData2 is zero.
};
union
{
WStringProxy *_secondString; //pointer to second string for OpConcat
unsigned long _offset; //offset of substring for OpSubstr
Effect _effect; //effect selector for OpEffect
IWStringEffect *_userEffect; //user effect defined by IWStringEffect interface (valid when _effect is invalid)
unsigned long _blockData2; //user defined block data for OpMemBlock proxy type - exception: if this value is zero, member _redirect is valid
};
void RenderStringToBuffer(wchar_t *renderPtr);
void RenderStringToBufferSubstr(wchar_t *renderPtr, size_t offset, size_t size);
WStringProxy *TransitivniUzaver();
void RenderSimpleEffect(wchar_t *renderPtr);
public:
WStringProxy():_refCount(0),_operation(OpSubstr),_stringSize(0),_baseString(0),_secondString(0) {} //inicializes empty string proxy
WStringProxy(WStringProxy *other):
_refCount(0),
_stringSize(other->GetLength()),
_baseString(other),
_operation(OpSubstr),
_offset(0)
{_baseString->AddRef();}
WStringProxy(WStringProxy *other, unsigned long offset, unsigned long size):
_refCount(0),
_stringSize(size),
_baseString(other),
_operation(OpSubstr),
_offset(offset)
{_baseString->AddRef();}
WStringProxy(WStringProxy *a, WStringProxy *b):
_refCount(0),
_stringSize(a->GetLength()+b->GetLength()),
_baseString(a),
_operation(OpConcat),
_secondString(b)
{_baseString->AddRef();_secondString->AddRef();}
WStringProxy(WStringProxy *a, Effect effect):
_refCount(0),
_stringSize(a->GetLength()),
_baseString(a),
_operation(OpEffect),
_effect(effect)
{_baseString->AddRef();}
WStringProxy(WStringProxy *a, IWStringEffect *userEffect):
_refCount(0),
_stringSize(a->GetLength()+userEffect->GetEffectExtraSize(a->GetLength())),
_baseString(a),
_operation(OpEffect),
_userEffect(userEffect)
{_baseString->AddRef();}
WStringProxy(unsigned long size, unsigned long user1, unsigned long user2):
_refCount(0),
_stringSize(size),
_operation(OpMemBlck),
_blockData(user1),
_blockData2(user2)
{}
WStringProxy(const wchar_t *imText):
_refCount(0),
_stringSize(wcslen(imText)),
_redirect(imText),
_blockData2(0),
_operation(OpMemBlck)
{}
WStringProxy(const WStringProxy &other)
{
memcpy(this,&other,sizeof(*this));
if (_operation!=OpMemBlck) _baseString->AddRef();
if (_operation==OpConcat) _secondString->AddRef();
}
WStringProxy& operator=(const WStringProxy &other)
{
WStringProxy::~WStringProxy(); //call destructor to destruct current proxy
memcpy(this,&other,sizeof(*this)); //construct new proxy from template
if (_operation!=OpMemBlck) _baseString->AddRef();
if (_operation==OpConcat) _secondString->AddRef();
}
WStringProxy *RenderString();
~WStringProxy()
{
if (_operation!=OpMemBlck) _baseString->Release();
if (_operation==OpConcat) _secondString->Release();
}
unsigned long GetLength() {return _stringSize;}
void AddRef() {if (this) WStringMemory::AddRefProxy(this);}
void Release() {if (this) if (WStringMemory::ReleaseRefProxy(this)) WStringMemory::FreeProxy(this);}
const wchar_t *GetString()
{
if (_operation==OpMemBlck) return (const wchar_t *)(this+1);
WStringProxy *p=RenderString();
(*this)=*p;
return (const wchar_t *)(p+1);
}
const wchar_t *GetStringFromMemBlock()
{
assert(_operation==OpMemBlck);
if (_blockData2==0 && _redirect!=NULL) return _redirect;
else return (const wchar_t *)(this+1);
}
bool IsShared() {return _refCount>1;}
void RecalcLength()
{
const wchar_t *str=GetStringFromMemBlock();
_stringSize=wcslen(str);
}
};
#endif // !defined(AFX_WSTRINGPROXY_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,49 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by DDLReader.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_DDLREADER_DIALOG 102
#define IDS_FILEOPENFAILED 102
#define IDC_HEADGROUP 103
#define IDC_HEADFNAME 104
#define IDC_HEADSIZE 105
#define IDC_HEADOFFSET 106
#define IDS_DDLFILTER 107
#define IDC_GROUP_GRAPHICS 108
#define IDC_GROUP_SOUNDS 109
#define IDC_GROUP_FONTS 110
#define IDC_GROUP_BASIC 111
#define IDC_GROUP_ITEMS 112
#define IDC_GROUP_MONSTERS 113
#define IDC_GROUP_DIALOGS 114
#define IDC_GROUP_UNSPECIFIED 115
#define IDC_GROUP_UNKNOWN 116
#define IDS_UNABLETOCREATEFILE 117
#define IDS_UNABLETOEXTACTDATA 118
#define IDR_MAINFRAME 128
#define IDD_PROGRESS 129
#define IDD_EXPORTING 129
#define IDC_FILELIST 1001
#define IDC_FOLDER 1002
#define IDC_BROWSE 1003
#define IDC_EXPORT 1004
#define IDC_POPISEK 1005
#define IDC_DDLFILE 1006
#define IDC_DDLBROWSE 1007
#define IDC_PROGRESS 1008
#define IDC_NAME 1009
#define IDC_BUTTON1 1010
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1011
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

8
DDLReader/StdAfx.cpp Normal file
View file

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// DDLReader.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

27
DDLReader/StdAfx.h Normal file
View file

@ -0,0 +1,27 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__C5BDACC6_729E_4CA2_B27E_A1F209FB32A7__INCLUDED_)
#define AFX_STDAFX_H__C5BDACC6_729E_4CA2_B27E_A1F209FB32A7__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include "wstring.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__C5BDACC6_729E_4CA2_B27E_A1F209FB32A7__INCLUDED_)

408
DDLReader/WPathname.cpp Normal file
View file

@ -0,0 +1,408 @@
// WPathname.cpp: implementation of the WPathname class.
//
//////////////////////////////////////////////////////////////////////
#include "WPathname.h"
#include <windows.h>
#include <shlobj.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
WPathname::WPathname(const wchar_t *name /*=NULL*/)
{
if (name) SetPathname(name);
}
WPathname::WPathname(const WString &name)
{
SetPathname(name);
}
WPathname::WPathname(const wchar_t *relpath, const WPathname &abspath)
{
_fullpath=WString(relpath);
int chr=_fullpath.FindLast('\\');
if (chr!=-1)
{
_path=_fullpath.Left(chr+1);
_filetitle=_fullpath.Right(chr+1);
}
else
{
_filetitle=_fullpath;
}
chr=_filetitle.FindLast('.');
if (chr!=-1)
{
_extension=_filetitle.Right(chr);
_filetitle=_filetitle.Left(chr);
}
RelativeToFull(abspath);
}
WPathname::WPathname(const WPathname &other)
{
_fullpath=other._fullpath;
_path=other._path;
_filetitle=other._filetitle;
_extension=other._extension;
}
void WPathname::SetDrive(wchar_t dr)
{
if (HasDrive())
{
if (dr==0) _path=_path.Right(2);
else _path[0]=dr;
}
else if (dr!=0)
{
int np=IsNetworkPath();
wchar_t buff[2];
buff[0]=dr;
buff[1]=':';
buff[2]=0;
if (np)
_path=WString(buff)+_path.Right(np);
else
_path=WString(buff)+_path;
}
RebuildPath();
}
void WPathname::SetDirectory(const wchar_t *dir)
{
bool copydrv; //directory doesn't contain drive, need copy from original
bool addslash; //directory doesn't ending by backslash, need add it
int len=wcslen(dir);
copydrv=HasDrive(dir) || !HasDrive(); //copy original drive, if exists and directory doesn't contaion drive
if (wcsncmp(dir,L"\\\\",2)==0) copydrv=true; //network path, don't copy drive
addslash=len && dir[len-1]!='\\'; //add slash
if (copydrv)
_path=WString(dir);
else
_path=_path.Left(2)+WString(dir);
if (addslash)
_path+=WSC("\\");
RebuildPath();
}
void WPathname::SetFilename(const wchar_t *filename)
{
WString wfilename=WString(filename);
int dot=wfilename.FindLast('.');
if (dot==-1)
{
_filetitle=wfilename;
_extension=0;
}
else
{
_filetitle=wfilename.Left(dot);
_extension=wfilename.Right(dot);
}
RebuildPath();
}
void WPathname::SetExtension(const wchar_t *ext)
{
_extension=WString(ext);
RebuildPath();
}
void WPathname::SetFileTitle(const wchar_t *title)
{
_filetitle=WString(title);
RebuildPath();
}
void WPathname::SetPathname(const wchar_t *pathname)
{
SetPathname(WString(pathname));
}
void WPathname::SetPathname(const WString &pathname)
{
if (pathname.GetLength()==0) SetNull();
else
{
wchar_t *part;
DWORD needsz=GetFullPathNameW(pathname,0,NULL,&part);
wchar_t *fpth=(wchar_t *)alloca(needsz*sizeof(*fpth));
GetFullPathNameW(pathname,needsz,fpth,&part);
part=wcsrchr(fpth,'\\');
if (part) part++;else part=NULL;
if (part)
{
SetFilename(part);
*part=0;
}
else
SetFilename(WString());
SetDirectory(fpth);
}
}
const wchar_t *WPathname::GetNameFromPath(const wchar_t *path)
{
const wchar_t *c=wcsrchr(path,'\\');
if (c!=NULL) c++;else return path;
return c;
}
const wchar_t *WPathname::GetExtensionFromPath(const wchar_t *path)
{
const wchar_t *fname=GetNameFromPath(path);
const wchar_t *c=wcsrchr(fname,'.');
if (c==NULL) c=wcsrchr(path,0);
return c;
}
void WPathname::RebuildPath()
{
_fullpath=_path+_filetitle+_extension;
}
bool WPathname::GetDirectoryWithDriveWLBS(wchar_t *buff, size_t size) const
{
size_t psize=wcslen(GetDirectoryWithDrive());
if (psize>size) return false;
if (psize==0) {buff[0]=0;return true;}
wcsncpy(buff,GetDirectoryWithDrive(),psize-1);
buff[psize-1]=0;
return true;
}
WString WPathname::GetDirectoryWithDriveWLBS() const
{
if (_path.GetLength()) return _path.Left(_path.GetLength()-1);
return WString();
}
bool WPathname::IsPathValid() const
{
if (IsNull()) return false;
wchar_t *invalidChars=L"/*?\"<>|";
const wchar_t *path=GetFullPath();
if (*path==0) return false;
while (*path)
{
if (wcschr(invalidChars,*path)!=NULL) return false;
path++;
}
return true;
}
bool WPathname::SetTempDirectory()
{
wchar_t buff[1];
DWORD size=GetTempPathW(1,buff);
if (size==0) return false;
WString pth;
wchar_t *p=pth.CreateBuffer(size);
if (GetTempPathW(size,p)==0) return false;
pth.UnlockBuffer();
_path=pth;
return true;
}
bool WPathname::SetDirectorySpecial(int nSpecCode)
{
wchar_t buff[MAX_PATH];
if (SHGetSpecialFolderPathW(GetForegroundWindow(),buff,nSpecCode,FALSE)!=NOERROR) return false;
SetDirectory(buff);
return true;
}
bool WPathname::SetTempFile(const wchar_t *prefix, unsigned int unique)
{
wchar_t tempname[MAX_PATH];
if (GetTempFileNameW(GetDirectoryWithDrive(),prefix,unique,tempname)==0) return false;
this->SetPathname(tempname);
return true;
}
WPathname WPathname::GetExePath()
{
wchar_t buff[MAX_PATH*4];
GetModuleFileNameW(NULL,buff,sizeof(buff));
return WPathname(buff);
}
const wchar_t *WPathname::FullToRelativeProjectRoot(const wchar_t *full, const wchar_t *projectRoot)
{
const wchar_t *a=full,*b=projectRoot;
while (*a && towlower(*a)==towlower(*b)) {a++;b++;};
if (*b) return full;
return a;
}
bool WPathname::FullToRelative(const WPathname &relativeto)
{
if (relativeto.IsNull() || IsNull()) return false;
bool h1=HasDrive();
bool h2=relativeto.HasDrive();
if (h1!=h2) return false; //rozdilny zpusob adresace - nelze vytvorit relatvni cestu
if (h1==true && h2==true && towupper(GetDrive())!=towupper(relativeto.GetDrive()))
return false; //ruzne disky, nelze vytvorit relativni cestu
if (wcsncmp(_path,L"\\\\",2)==0) //sitova cesta
{
int slsh=0; //citac lomitek
const wchar_t *a=_path;
const wchar_t *b=relativeto._path;
while (towupper(*a)==towupper(*b) && *a && slsh<3) //zacatek sitove cesty musi byt stejny
{
if (*a=='\\') slsh++;
a++;b++;
}
if (slsh!=3) return false; //pokud neni stejny, nelze vytvorit relativni cestu
}
int sublevel=0;
const wchar_t *ps1=_path;
const wchar_t *ps2=relativeto._path;
if (h1) {ps1+=2;ps2+=2;}
const wchar_t *sls=ps2;
while (towupper(*ps1)==towupper(*ps2) && *ps1)
{
if (*ps2=='\\') sls=ps2+1;
ps1++;ps2++;
}
ps1-=ps2-sls;
if (sls)
{
while (sls=wcschr(sls,'\\'))
{
sls++;
sublevel++;
}
}
wchar_t *buff=(wchar_t *)alloca((sublevel*3+wcslen(ps1)+1)*sizeof(*buff));
wchar_t *pos=buff;
for (int i=0;i<sublevel;i++)
{wcscpy(pos,L"..\\");pos+=3;}
wcscpy(pos,ps1);
SetDrive(0);
SetDirectory(buff);
return true;
}
bool WPathname::RelativeToFull(const WPathname &ref)
{
if (ref.IsNull() || IsNull()) return false;
const wchar_t *beg;
if (HasDrive())
if (towupper(GetDrive())!=towupper(ref.GetDrive())) return false;
else beg=_path+2;
else beg=_path;
const wchar_t *end=wcschr(ref._path,0);
if (beg[0]=='\\')
{
int np;
if (ref.HasDrive()) end=ref._path+2;
else if (np=ref.IsNetworkPath()) end=ref._path+np;
else end=ref._path;
}
else while (wcsncmp(beg,L"..\\",3)==0 || wcsncmp(beg,L".\\",2)==0)
{
if (beg[1]=='.')
{
if (end>ref._path.GetString())
{
end--;
while (end>ref._path.GetString() && end[-1]!='\\') end--;
}
beg+=3;
}
else
beg+=2;
}
int partln=end-ref._path;
wchar_t *buff=(wchar_t *)alloca((partln+wcslen(beg)+1)*sizeof(*buff));
wcsncpy(buff,ref._path,partln);
wcscpy(buff+partln,beg);
SetDrive(0);
SetDirectory(buff);
return true;
}
int WPathname::IsNetworkPath() const
{
if (wcsncmp(_path,L"\\\\",2)==0) //sitova cesta
{
const wchar_t *p=_path+2;
const wchar_t *c=wcschr(p,'\\');
if (c) return c-_path;
}
return 0;
}
void WPathname::SetServerName(const wchar_t *server)
{
if (HasDrive()) SetDrive(0);
else
{
int np=IsNetworkPath();
_path=_path.Right(np);
}
_path=WSC("\\\\")+WString(server)+WSC("\\");
RebuildPath();
}
void WPathname::SetNull()
{
_fullpath=_path=_filetitle=_extension=0;
}
bool WPathname::GetPartFromPath(const wchar_t *path, int partnum, wchar_t *buff, int bufsize, int mode)
{
const wchar_t *scan=path;
while (*scan=='\\') scan++;
while (partnum && *scan)
{
while (*scan!='\\' && *scan) scan++;
while (*scan=='\\') scan++;
partnum--;
}
if (*scan==0)
{
buff[0]=0;
return false;
}
int pt=0;
if (mode==-1)
{
pt=scan-path;
if (pt>bufsize)
{
buff[0]=0;
return true;
}
else
memcpy(buff,path,pt);
}
bool nlast=false;
while (*scan && (mode==1 || !nlast) && pt<bufsize)
{
buff[pt]=*scan;
pt++;
scan++;
if (*scan=='\\') nlast=true;
}
if (pt==bufsize)
{
buff[0]=0;
return true;
}
buff[pt]=0;
return nlast;
}

400
DDLReader/WPathname.h Normal file
View file

@ -0,0 +1,400 @@
// WPathname.h: interface for the WPathname class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WPathname_H__158F59D5_B422_4FA6_86AC_10B5EC48C81B__INCLUDED_)
#define AFX_WPathname_H__158F59D5_B422_4FA6_86AC_10B5EC48C81B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "WString.h"
#ifndef ASSERT
#ifdef _DEBUG
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif
#endif
#define WPathnameCompare(op) bool operator op (const WPathname &other) const \
{if (IsNull() || other.IsNull()) return false;else return wcsicmp(_fullpath,other._fullpath) op 0;}\
bool operator op (const wchar_t *other) const \
{ASSERT(!other || other[0]!=0);\
if (IsNull() || other==NULL) return false;else return wcsicmp(_fullpath,other) op 0;}
/** class WPathname simplifying manipulation with WPathnames, filenames, general paths, and
also supports convert from absolute path to relative respectively */
class WPathname
{
///object value and data
/**The implementation of WPathname creates only one buffer for all variables. It can
increase speed by effective memory use. Strings are stored one after another separated
by zero byte. Evry time any string changed, implementation recalculate buffer usage, and
decide, whether it should resize buffer or not.
_fullpath also points to string contain full path with filename,
it is dominant value of the class
*/
WString _fullpath;
WString _path; ///<current path with drive
WString _filetitle; ///<file title without extension
WString _extension; ///<file extension
public:
///Construct WPathname class.
/** If name is not provided, current path is used, and as filename, WPathname suppl wildcards
*.* . That is useful, for searching in directory.<br>
If name is provided, WPathname will expand it into full name with drive and folder name.
@param name optional argument to inicialize object
*/
WPathname(const wchar_t *name=NULL);
WPathname(const WString &name);
///Construct WPathname class
/**
@param relpath Relative path or uncomplette path or single filename with extension.
WPathname will expand this WPathname into full using absolute path provided by the second
argument.
@param abspath Absolute path used as reference to folder - the origin of relative path
provided in the first argument.
*/
WPathname(const wchar_t *relpath, const WPathname &abspath);
///Construct WPathname as copy of another WPathname
WPathname(const WPathname &other);
///Function returns the current drive letter.
/** Before usage, ensure, that current WPathname contain drive.
In network path drive letter is missing.
In this case, result is undefined. To ensure, use HasDrive function
@return the drive letter of current path.
*/
wchar_t GetDrive() const
{
if (IsNull()) return 0;
return _path[0];
}
///Static function determines, if argument contain a drive information.
/**
@param dir directory to inspect
@return true, if directory contain drive.<p>
This function is independed, it don't need any WPathname variable declared.
*/
static bool HasDrive(const wchar_t *dir)
{return (dir[0]>='A' && dir[0]<='Z' || dir[0]>='a' && dir[0]<='z') && dir[1]==':';}
///Function determines, if current WPathname contain a drive information
/**
@return true, if current WPathname contain a drive information
*/
bool HasDrive() const
{
if (IsNull()) return false;
return HasDrive(_path);
}
///Function returns current folder name
/**
if current folder name contain drive, only folder name is returned (without drive).
In other cases (relative or network drives) returns full path.
@return folder name or full path. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetDirectory() const
{
if (HasDrive()) return _path.GetString()+3;
else return _path.GetString()+IsNetworkPath();
}
const wchar_t *GetDirectoryWithDrive() const
{
return _path;
}
///Function returns current filename with extension
/**
@return current filename with extension. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetFilename() const
{
if (IsNull()) return NULL;
const wchar_t *blk=wcsrchr(_fullpath,'\\');
if (blk) blk=blk+1;else blk=_fullpath;
return blk;
}
///Function returns current extension (with starting dot)
/**
@return current extension. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetExtension() const
{return _extension;}
///Function returns current filename without extension (without dot)
/**
@return current filename without extension (without dot). Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetTitle() const
{return _filetitle;}
///Function changes current drive.
/**If object contain WPathname with drive, then current drive is changed and function returns.
If object contain network path, then computer name is changed to the drive name.
If object contain relative path, then whole path is replaced by path on root on drive.
@param dr new drive letter. This parameter can be set to zero. It means, that current
driver is deleted, and path is converted to relative path from root. Note: Zero c
cannot be used with network paths and relative paths, and finnaly has no effect to the object
*/
void SetDrive(wchar_t dr);
///Sets new directory for object
/** if object contain a drive letter and argument dir doesn't, then current drive is remain
and only directory part is replaced. If current path is network path or relative path,
then whole path is replaced by new one.
If argument dir contain drive letter, then whole path is replaced too.
@param dir contain new WPathname. Backslash should be the last wchar_tacter in string
*/
void SetDirectory(const wchar_t *dir);
///Sets new filename for object.
/**
If filename contain dot, function assumes, that filename is provided with extension.
Otherwise, current extension remains untouched.
@param filename new filename for object
*/
void SetFilename(const wchar_t *filename);
///Sets new extension for object.
/**
If ext doesn't starting with dot, function adds it.
@param ext new extension for object
*/
void SetExtension(const wchar_t *ext);
///Sets new file title
/** Function changes file title, extension remains untouched.
if title contains extension (dot inside its name), this extension doesn't change
current extension. For example, if current extension is ".cpp" and filetitle contain
"source.h", then result is "source.h.cpp"
@param title a new title for object.
*/
void SetFileTitle(const wchar_t *title);
///Function returns full WPathname.
/**
@return current WPathname. Pointer is valid until any first change in object.
Do not invoke release function at pointer!
*/
const wchar_t *GetFullPath() const
{return _fullpath;}
///Sets WPathname
/** Function has same effect as constructor. But it can be used
anytime during object lifetime. It simply replaces current WPathname with newer. WPathname
in argument is expanded to full WPathname, current directory is used as reference.
@param WPathname new WPathname
*/
void SetPathname(const wchar_t *pathname);
void SetPathname(const WString &pathname);
WPathname& operator=(const wchar_t *other)
{SetPathname(other);return *this;}
WPathname& operator=(const WString &other)
{SetPathname(other);return *this;}
WPathname& operator=(const WPathname& other)
{
_fullpath=other._fullpath;
_path=other._path;
_filetitle=other._filetitle;
_extension=other._extension;
return *this;
}
///converts object to string
operator const wchar_t *() const
{return GetFullPath();}
///Static function to help getting filename from WPathname
/** Function finds last backslash / and return pointer to first wchar_tacter after it.
Pointer stays valid until original path is destroyed or until original path is changed
@param path WPathname to inspect as string
@return pointer to filename
*/
static const wchar_t *GetNameFromPath(const wchar_t *path);
///Static function to help getting extension from WPathname
/** Function finds last dot '.' in filename return pointer to it (extension with dot).
Pointer stays valid until original path is destroyed or until original path is changed
@param path WPathname to inspect as string
@return pointer to extension
*/
static const wchar_t *GetExtensionFromPath(const wchar_t *path);
///Function sets server name for network path
/** If current path is network path, then changes server name to newer. Otherwise
it remove drive letter, and insert server name before remain path
@param server server name without slashes
*/
void SetServerName(const wchar_t *server);
///Function inspects current path and returns, whether contain server name
/**@return zero, if current path is not valid network path. Nonzero if path contain
server name. Then value returned count wchar_tacters containing server name with precedent
slashes.
*/
int IsNetworkPath() const;
///Function converts current relative path into absolute path
/**
If current path is not relative, function do nothing.
@param ref reference to path, against which path is relative.
@return true if path has been converted, or false, if conversion is impossible
*/
bool RelativeToFull(const WPathname &ref);
///Function converts current absolute path into relative path
/**
If current path is not relative, function do nothing. Both paths must be on the same
drive or network computer.
@param ref reference to path, against which path should be relative.
@return true if path has been converted, or false, if conversion is impossible
*/
bool FullToRelative(const WPathname &relativeto);
WPathname& operator+=(const wchar_t *relativePath)
{*this=WPathname(relativePath,*this);return *this;}
WPathname operator+(const wchar_t *relativePath)
{WPathname out(relativePath,*this);return out;}
bool IsNull() const {return _fullpath.GetLength()==0;}
void SetNull();
WPathnameCompare(<)
WPathnameCompare(>)
WPathnameCompare(==)
WPathnameCompare(>=)
WPathnameCompare(<=)
WPathnameCompare(!=)
///Function gets part of WPathname
/**
@param path subject of examine
@param partnum zero-base index of part of WPathname. Index 0 mostly contain drive or server, in case of
relative path, there is the name of the first folder or dots.
@param buff buffer for store result
@param bufsize count wchar_tacters in buffer;
@param mode mode=0, gets only name of part.
mode=1, get current part and remain parts of path.
mode=-1, gets all parts till current
@return Function returns true, if it was succesful, and it was not last part. Function returns
false, if it was succesful, and it was last part. Function returns false and sets buffer empty,
if an error occured. Function returns true and sets buffer empty, if buffer is too small to hold data
*/
static bool GetPartFromPath(const wchar_t *path, int partnum, wchar_t *buff, int bufsize, int mode=0);
///Function gets part of object
/**
@param partnum zero-base index of part of WPathname. Index 0 mostly contain drive or server, in case of
relative path, there is the name of the first folder or dots.
@param buff buffer for store result
@param bufsize count wchar_tacters in buffer;
@param mode mode=0, gets only name of part.
mode=1, get current part and remain parts of path.
mode=-1, gets all parts till current
@return Function returns true, if it was succesful, and it was not last part. Function returns
false, if it was succesful, and it was last part. Function returns false and sets buffer empty,
if an error occured. Function returns true and sets buffer empty, if buffer is too small to hold data
*/
bool GetPart(int partnum, wchar_t *buff, int bufsize,int mode=0) const
{
return GetPartFromPath(this->_fullpath,partnum,buff,bufsize,mode);
}
/// Get Directory With Drive Without Last Back Slash
/** Retrieves into buffer directory with drive and removes last backslash
@param buff buffer that retrieves path
@param size size of buffer
@return true, if success, failed if buffer is too small*/
bool GetDirectoryWithDriveWLBS(wchar_t *buff, size_t size) const;
WString GetDirectoryWithDriveWLBS() const;
/// function checks, if path is valid and returns true, if does.
bool IsPathValid() const;
/// Sets special directory.
/**
@param bSpecCode this value may be operation-system
depend. Windows implementation using CSIDL_XXXX constants, which is described in SHGetSpecialFolderLocation function
description
@return true, if function were successful
*/
bool SetDirectorySpecial(int nSpecCode);
///Sets temporaly directory.
bool SetTempDirectory();
///Guess temporaly file name
/**
@param prefix prefix string for name
@param unique if unique is non-zero, it is used for new temporaly file. If unique is zero, function guess own unique
value.
@return true if function were successful
*/
bool SetTempFile(const wchar_t *prefix=L"tmp", unsigned int unique=NULL);
///Returns path of current executable.
/**It useful, when accessing folder, from when current module has been executed */
static WPathname GetExePath();
///Solves most used conversion from fullpath to path relative to project root
/**
@param full full WPathname with drive
@param projectRoot project root path
@return function returns pointer to full path, where starts relative part. If
fullpath doesn't contain project root path, it returns pointer to full.
@example FullToProjectRoot("x:\\project\\data\\example.txt","x:\\project"); //result is "data\\example.txt"
*/
static const wchar_t *FullToRelativeProjectRoot(const wchar_t *full, const wchar_t *projectRoot);
protected:
///Function only rebuild _fullpath string.
/** It doesn't check space for string! This function is used, when length of path is excepted
the same or smaller, then current.
*/
void RebuildPath();
};
#endif // !defined(AFX_WPathname_H__158F59D5_B422_4FA6_86AC_10B5EC48C81B__INCLUDED_)

194
DDLReader/WString.cpp Normal file
View file

@ -0,0 +1,194 @@
// WString.cpp: implementation of the WString class.
//
//////////////////////////////////////////////////////////////////////
#include "WString.h"
#include <windows.h>
#include <stdio.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
WString::WString(const char *sbstring, unsigned int codePage)
{
if (sbstring==NULL || *sbstring==0)
{
_ref=NULL;
}
else
{
size_t reqBuff=MultiByteToWideChar(codePage,0,sbstring,-1,NULL,0);
_ref=WStringMemory::AllocString(NULL,reqBuff);
_ref->AddRef();
wchar_t *str=const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
MultiByteToWideChar(codePage,0,sbstring,-1,str,reqBuff);
}
}
int WString::FormatV(wchar_t *format, va_list lst)
{
size_t curSize=4096;
int written;
do
{
_ref=WStringMemory::AllocString(NULL,curSize);
wchar_t *str=const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
written=_vsnwprintf(str,curSize,format,lst);
if (written<0)
{
curSize*=2;
WStringMemory::FreeProxy(_ref);
}
}
while (written<-1);
_ref->RecalcLength();
_ref->AddRef();
return written;
}
int WString::Format(wchar_t *format, ...)
{
va_list valst;
va_start(valst,format);
return FormatV(format,valst);
}
int WString::ScanStringV(const wchar_t *format, va_list lst) const
{
unsigned long *ptr=(unsigned long *)lst;
return swscanf(GetString(),format,ptr[0],ptr[1],ptr[2],ptr[3],ptr[4],ptr[5],ptr[6],ptr[7],ptr[8],ptr[9],
ptr[10],ptr[11],ptr[12],ptr[13],ptr[14],ptr[15],ptr[16],ptr[17],ptr[18],ptr[19]);
}
int WString::ScanString(const wchar_t *format, ...) const
{
va_list valst;
va_start(valst,format);
return ScanStringV(format,valst);
}
bool WString::ReplaceOnce(const WString &findWhat,const WString &replaceWith)
{
int pos=Find(findWhat);
if (pos==-1) return false;
(*this)=Left(pos)+replaceWith+Right(pos+replaceWith.GetLength());
return true;
}
bool WString::ReplaceAll(const WString &findWhat,const WString &replaceWith)
{
WString process=*this;
WString result;
int pos;
bool processed=false;
while ((pos=process.Find(findWhat))!=-1)
{
result=result+process.Left(pos)+replaceWith;
process=process.Right(pos+findWhat.GetLength());
processed=true;
}
*this=result+process;
return processed;
}
WString WString::TrimLeft() const
{
return TrimLeft(L" \r\n\t");
}
WString WString::TrimRight() const
{
return TrimRight(L" \r\n\t");
}
WString WString::TrimLeft(wchar_t *trimChars) const
{
const wchar_t *proStr=GetString();
int p=0;
while (proStr[p] && wcschr(trimChars,proStr[p]!=NULL)) p++;
return Right(p);
}
WString WString::TrimRight(wchar_t *trimChars) const
{
const wchar_t *proStr=GetString();
int p=GetLength()-1;
while (p>=0 && wcschr(trimChars,proStr[p]!=NULL)) p--;
return Left(p+1);
}
WString WString::Upper() const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,WStringProxy::EfUpper)));
}
WString WString::Lower() const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,WStringProxy::EfLower)));
}
WString WString::Reverse() const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,WStringProxy::EfReverse)));
}
WString WString::Effect(IWStringEffect *effect) const
{
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,effect)));
}
void WString::SetUTF7(const char *utf7)
{
*this=WString(utf7,CP_UTF7);
}
void WString::SetUTF8(const char *utf8)
{
*this=WString(utf8,CP_UTF8);
}
const char *WString::AsSBString(unsigned int codePage, WString &holder)
{
const wchar_t *str=GetString();
if (str[0]==0) return "";
size_t reqsize=WideCharToMultiByte(codePage,0,str,-1,NULL,0,NULL,NULL);
WStringProxy *holderProxy=WStringMemory::AllocString(NULL,reqsize/2); //reqsize/2+(2 bytes)
char *mbstr=reinterpret_cast<char *>(const_cast<wchar_t *>(holderProxy->GetStringFromMemBlock()));
WideCharToMultiByte(codePage,0,str,-1,mbstr,reqsize,NULL,NULL);
holder=WString(holderProxy);
return mbstr;
}
const char *WString::AsUTF7(WString &holder)
{
return AsSBString(CP_UTF7,holder);
}
const char *WString::AsUTF8(WString &holder)
{
return AsSBString(CP_UTF8,holder);
}
void WString::ReadFromStream(size_t (*streamReader)(wchar_t *buffer, size_t bufferLen, void *context),void *context)
{
_ref->Release();
_ref=NULL;
wchar_t buff[256];
size_t rd;
while ((rd=streamReader(buff,sizeof(buff)/sizeof(wchar_t),context))!=0)
{
*this=*this+WString(buff,rd);
}
}
const WString WStringConst(const wchar_t *text)
{
return WString(WStringMemory::AllocProxy(WStringProxy(text)));
}

496
DDLReader/WString.h Normal file
View file

@ -0,0 +1,496 @@
// WString.h: interface for the WString class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WSTRING_H__481164FB_3BB7_4824_B0E3_8B371F0AAF3A__INCLUDED_)
#define AFX_WSTRING_H__481164FB_3BB7_4824_B0E3_8B371F0AAF3A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "WStringProxy.h"
#include <stdlib.h>
class WString
{
mutable WStringProxy *_ref;
public:
///constructs empty string
WString():_ref(0) {}
///constructs string.
explicit WString(const wchar_t *string):_ref(string==NULL?NULL:WStringMemory::AllocString(string,0)) {_ref->AddRef();};
///constructs string from wide-char array with specified length
WString(const wchar_t *string, size_t sz):_ref(WStringMemory::AllocString(string,sz)) {_ref->AddRef();};
///copy constructor
/**constructor doesn't copy the string, only reference.
String is shared until it is changed
*/
WString(const WString &other):_ref(other._ref) {_ref->AddRef();}
///constructs string from multi-byte string. codePage specified code page of string
WString(const char *sbstring, unsigned int codePage);
///constructs string from string-proxy. Used internally with WStringMemory::AllocXXX functions
WString(WStringProxy *proxy):_ref(proxy) {_ref->AddRef();}
///assignment operator
/** assignment operator doesn't copy the string only reference.
String is shared until it is changed */
WString &operator=(const WString &other)
{other._ref->AddRef();_ref->Release();_ref=other._ref;return *this;}
///Destructor - releases reference
~WString() {_ref->Release();}
///function converts instance of WString to wchar_t pointer
/**
Function will perform RenderString, if it is needed.
*/
const wchar_t *GetString() const
{
if (_ref==NULL) return L"";
WStringProxy *str=_ref->RenderString();
if (_ref!=str)
{
str->AddRef();_ref->Release();_ref=str;
}
return _ref->GetStringFromMemBlock();
}
///operator can convert WString to wchar_t pointer anytime
operator const wchar_t *() const {return GetString();}
///function returns count of characters in string
/** function doesn't need to render string, so it can be called anytime
without loosing the benefit of "pseudo-strings" boosting */
size_t GetLength() const
{
if (_ref) return _ref->GetLength();
else return 0;
}
///function creates string as sum of this and another string
/** function creates "pseudo-string" that represents sum of two string.
pseudo-string is rendered to "real-string" automatically, when it is needed */
WString operator+(const WString other) const
{
if (_ref==NULL) return other;
if (other._ref==NULL) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,other._ref)));
}
WString &operator+=(const WString other)
{
*this=*this+other;
return *this;
}
///function creates string as substring of another string
/** function creates "pseudo-string" that represents substring of anothers string.
Pseudo-string is rendered to "real-string" automatically, when it is needed */
WString Mid(size_t begin, size_t len) const
{
if (begin==0) return Left(len);
if (_ref==NULL || begin>GetLength()) return WString();
if (begin+len>GetLength()) return Right(begin);
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,begin,len)));
}
WString Left(size_t len) const
{
if (_ref==NULL) return WString();
if (len>=GetLength()) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,0,len)));
}
WString Right(size_t begin) const
{
if (_ref==NULL || begin>GetLength()) return WString();
if (begin==0) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,begin,GetLength()-begin)));
}
WString RightR(size_t count) const
{
if (_ref==NULL || count==0) return WString();
if (count>=GetLength()) return *this;
return WString(WStringMemory::AllocProxy(WStringProxy(_ref,GetLength()-count,count)));
}
WString Delete(size_t begin, size_t count) const
{
if (_ref==NULL) return WString();
if (begin==0) return Right(count);
if (begin+count>=GetLength()) return Left(begin);
return WString(WStringMemory::AllocProxy(WStringProxy(Left(begin)._ref,Right(begin+count)._ref)));
}
WString Insert(const WString &what, size_t index) const
{
if (_ref==NULL) return what;
if (index==0) return what+*this;
if (index>=GetLength()) return *this+what;
return Left(index)+what+Right(index);
}
/// function allows to access any char in string
wchar_t operator[](int index) const
{
assert(index<=(int)GetLength() && index>=0);
return GetString()[index];
}
/// functions allows lock string for accesing it directly.
/** Function returns pointer to buffer which holds string.
Buffer size is equal to string length plus terminating zero.
Application can modify content of buffer.
If string is shared with another WString object, LockBuffer
creates copy of string
Do not forger to call UnlockBuffer, when you finish modifiing the content
*/
wchar_t *LockBuffer()
{
if (_ref==NULL) return NULL;
GetString();
WStringMemory::LockProxy(_ref);
if (_ref->IsShared())
{
WStringMemory::UnlockProxy(_ref);
_ref->Release();
_ref=WStringMemory::AllocString(_ref->GetStringFromMemBlock(),0);
_ref->AddRef();
WStringMemory::LockProxy(_ref);
}
return const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
}
/// Function creates buffer for string and returns its address
/** Application can use buffer in functions, that cannot work with
WString objects. Size of buffer is specified by sz value, and it is in characters.
Application must call UnlockBuffer after writes all data into buffer.
NOTE: Prevoius content of string is lost.
NOTE: sz specifies buffer size without terminating zero character
*/
wchar_t *CreateBuffer(size_t sz)
{
_ref->Release();
_ref=WStringMemory::AllocString(NULL,sz);
_ref->AddRef();
WStringMemory::LockProxy(_ref);
return const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
}
/// Function creates buffer, and copies string into it.
/** Parameter sz specifies size of new buffer in characters
When sz is smaller then size of string, string is truncated
When sz is larger then size of string, string is copied unchanged,
but extra characters can be appended.
NOTE: sz specifies buffer size without terminating zero character
*/
wchar_t *CreateBufferCopy(size_t sz)
{
WString save=*this;
wchar_t *wbuff=CreateBuffer(sz);
int minsz=__min(sz,save.GetLength());
wcsncpy(wbuff,save.GetString(),minsz);
return wbuff;
}
/// Function unlocks internal buffer
/** parameter sz specifies final lenght of string in buffer. Default
value -1 forces function calc size by own
*/
void UnlockBuffer(int sz=-1)
{
if (_ref==NULL) return;
wchar_t *wbuff=const_cast<wchar_t *>(_ref->GetStringFromMemBlock());
if (sz<0) sz=wcslen(wbuff);
else wbuff[sz]=0;
if (sz!=(signed)_ref->GetLength())
{
_ref->RecalcLength();
WStringMemory::UnlockProxy(_ref);
}
}
class WStringAtCharHelper
{
WString &_str;
size_t _index;
public:
WStringAtCharHelper(WString &str,size_t index):_str(str),_index(index) {}
WString &operator=(wchar_t z)
{
wchar_t *buff=_str.LockBuffer();
assert(buff && _index<_str.GetLength());
buff[_index]=z;
_str.UnlockBuffer();
return _str;
}
operator wchar_t()
{
assert(_index<_str.GetLength());
return ((const wchar_t *)_str)[_index];
}
};
/// Function will return helper object, which can access single character in string
/**
Using array operator is slower than accessing characters by LockBuffer function
*/
WStringAtCharHelper operator[](int index)
{
return WStringAtCharHelper(*this,index);
}
int Find(wchar_t z,size_t from=0) const
{
if (from>=GetLength()) return -1;
const wchar_t *res=wcschr(GetString()+from,z);
if (res) return res-GetString();
else return -1;
}
int FindLast(wchar_t z) const
{
const wchar_t *res=wcsrchr(GetString(),z);
if (res) return res-GetString();
else return -1;
}
int Find(const wchar_t *z,size_t from=0) const
{
if (z==NULL) return -1;
if (from>=GetLength()) return -1;
const wchar_t *res=wcsstr(GetString()+from,z);
if (res) return res-GetString();
else return -1;
}
int FormatV(wchar_t *format, va_list lst);
int Format(wchar_t *format, ...);
///Scans string for format
/** function is limited, item count is limited up to 20 items */
int ScanStringV(const wchar_t *format, va_list lst) const;
///Scans string for format
/** function is limited, item count is limited up to 20 items */
int ScanString(const wchar_t *format, ...) const;
bool ReplaceOnce(const WString &findWhat,const WString &replaceWith);
bool ReplaceAll(const WString &findWhat,const WString &replaceWith);
WString TrimLeft() const;
WString TrimRight() const;
WString TrimLeft(wchar_t *trimChars) const;
WString TrimRight(wchar_t *trimChars) const;
///Function splits string into two
/** Left part of string is returned.
Right part of string is leaved in object
@param splitPos split position.
@return if splitPos==0, function returns empty string. if splitPos>=length, function
moves string from object to result*/
WString Split(size_t splitPos)
{
WString result=Left(splitPos);
*this=Right(splitPos);
return result;
}
bool IsEmpty() const {return _ref==NULL;}
void Empty() const {_ref->Release();_ref=NULL;}
int Compare(const wchar_t *other) const
{
return wcscmp(*this,other);
}
bool operator>(const WString &other) const {return Compare(other)>0;}
bool operator<(const WString &other) const {return Compare(other)<0;}
bool operator>=(const WString &other) const {return Compare(other)>=0;}
bool operator<=(const WString &other) const {return Compare(other)<=0;}
bool operator!=(const WString &other) const {return Compare(other)<=0;}
bool operator==(const WString &other) const {return Compare(other)<=0;}
WString Upper() const;
WString Lower() const;
WString Reverse() const;
///Applies user effect on string
/** pointer should be static allocated object, or must be valid during lifetime of resulting string */
WString Effect(IWStringEffect *effect) const;
void SetUTF7(const char *utf7);
void SetUTF8(const char *utf8);
///Function converts string to SingleByte string
/**
@param codePage Platform depends code page of result
@param holder Object that holds result. Result pointer is valid during lifetime of holder. Once holder
released, pointer is invalidated. You can get resulting pointer anytime from holder reintepreting
wchar_t to char
@result pointer to string
*/
const char *AsSBString(unsigned int codePage, WString &holder);
///Returns multibyte string in UTF7 codepage
/**See AsSBString description*/
const char *AsUTF7(WString &holder);
///Returns multibyte string in UTF7 codepage
/**See AsSBString description*/
const char *AsUTF8(WString &holder);
///Function reads string from stream
/**
Function calls streamReader repeatly until function returns zero. In each call, streamReader returns
number of characters, that has been readed.
@param sreamReader pointer to function which provides reading from a stream
@param context user defined context pointer (most in cases, pointer to stream is passed)
@param buffer space allocated for data readed from stream
@param bufferLen maximum count of characters can be written to buffer
@return streamReader returns number of characters, that has been written to buffer. Function must return zero
to stop reading
*/
void ReadFromStream(size_t (*streamReader)(wchar_t *buffer, size_t bufferLen, void *context),void *context);
WString operator() (int from) const {return from<0?RightR(-from):Right(from);}
WString operator() (int from, int to) const
{
if (from>=0)
return to<0?Mid(from,-to):Mid(from,to-from);
else
return to<0?Mid(GetLength()+from,-to):Mid(GetLength()+from,GetLength()-from-to);
}
///Enables global string sharing.
/** Function Share allows share strings that contains same text. It can reduce memory
usage. Function is useful when there is many objects that contains string with same text.
Basically, two strings is shared, if one string is created as copy of another string. Strings
is sharing they content, until one of them is modified.
Calling Share function, string is registered for global sharing. If string with same content is already
registered, then content of current string is released, and string is shared.
To successfully share two strings, both strings must call Share() function. Sharing is provided until one
of strings is modified. After modifications are done, Share function of modified string must be called again.
Remember: Global sharing can reduce amount of memory, if there are multiple strings that containging
the same content. But sharing of each unique string takes small piece of memory to store sharing
informations.
To share string automatically, use WSharedString class
WSC strings cannot be shared!
*/
void Share() const
{
WStringProxy *curref=_ref;
GetString();
_ref=WStringMemory::ShareString(curref);
_ref->AddRef();
curref->Release();
}
///Disables global string sharing
/** Function unregisters string from global sharing database. If string is shared, function doesn't break
it. But all strings that currently sharing content will not be shared with newly created strings.
*/
void Unshare()
{
WStringMemory::UnshareString(_ref);
}
};
///Function will create constant WString
/** function will not copy content of string. Only creates reference to string
Using WStringConst is faster for strings in code
@exmple result=a+WStringConst(L"text")+b;
*/
const WString WStringConst(const wchar_t *text);
///Macro to easy convert incode string to WString
/**
function also marks text wide.
@example WString text=WSC("Hello world");
*/
#define WSC(x) WStringConst(L##x)
///Macro to easy convert any wchar_t buffer to constant WString
/**
IMPORTANT NOTE!: Buffer must exists until string is rendered.
If you are using WSCB in function, don't forget call GetString before function exits
If you are excepting additional string operations outside function, using standard
WString conversion can be more effecient.
*/
#define WSCB(x) WStringConst(x)
class WSharedString: public WString
{
public:
WSharedString() {}
///constructs string.
explicit WSharedString(const wchar_t *string):WString(string) {Share();}
///constructs string from wide-char array with specified length
WSharedString(const wchar_t *string, size_t sz):WString(string,sz) {Share();};
///copy constructor
/**constructor doesn't copy the string, only reference.
String is shared until it is changed
*/
WSharedString(const WSharedString &other):WString(other) {}
WSharedString(const WString &other):WString(other) {Share();}
///constructs string from multi-byte string. codePage specified code page of string
WSharedString(const char *sbstring, unsigned int codePage):WString(sbstring,codePage) {Share();}
///assignment operator
/** assignment operator doesn't copy the string only reference.
String is shared until it is changed */
WSharedString &operator=(const WString &other)
{WString::operator =(other);Share();return *this;}
const wchar_t *GetString() const
{
const wchar_t *res=WString::GetString();
Share();
return res;
}
operator const wchar_t *() const {return GetString();}
wchar_t operator[](int index) const
{
assert(index<=(int)GetLength() && index>=0);
return GetString()[index];
}
void UnlockBuffer(int sz=-1)
{
WString::UnlockBuffer(sz);
Share();
}
};
#endif // !defined(AFX_WSTRING_H__481164FB_3BB7_4824_B0E3_8B371F0AAF3A__INCLUDED_)

397
DDLReader/WStringMemory.cpp Normal file
View file

@ -0,0 +1,397 @@
// WStringMemorySingleThread.cpp: implementation of the WStringMemory class.
//
//////////////////////////////////////////////////////////////////////
#include <malloc.h>
#include <windows.h>
#include "WStringMemory.h"
#include "WStringProxy.h"
#include <assert.h>
#include <stdio.h>
#include <projects/btree/btree.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifdef _MT //multithreading
#define WSTRING_MT
#endif
#ifdef WSTRING_MT //multithreading
struct WStringMTLock
{
WStringProxy *_lockProxy;
LONG _recursionCount;
DWORD _owner;
HANDLE _event;
WStringMTLock(WStringProxy *x):_lockProxy(x) {}
WStringMTLock():_lockProxy(NULL) {}
bool operator==(const WStringMTLock &other) const {return _lockProxy==other._lockProxy;}
bool operator!=(const WStringMTLock &other) const {return _lockProxy!=other._lockProxy;}
bool operator>=(const WStringMTLock &other) const {return _lockProxy>=other._lockProxy;}
bool operator<=(const WStringMTLock &other) const {return _lockProxy<=other._lockProxy;}
bool operator>(const WStringMTLock &other) const {return _lockProxy>other._lockProxy;}
bool operator<(const WStringMTLock &other) const {return _lockProxy<other._lockProxy;}
int operator=(int zero) {_lockProxy=NULL;return zero;}
};
static CRITICAL_SECTION GLocker={{0},-1,0,0,0,0};
static HANDLE GLockProxy=NULL; //event object to notify waiters that somebody unlocks;
static BTree<WStringMTLock> *GLockDB=NULL; //Lock proxy database
static void exitMT()
{
DeleteCriticalSection(&GLocker);
}
static void OnStartup()
{
InitializeCriticalSection(&GLocker);
atexit(exitMT);
}
#define ON_STARTUP_PRIORITY_NORMAL OnStartup
#include <Es/Common/Startup.hpp>
#endif
#define WS_MAXFREELISTS 32
#define WS_FREELISTSTEP 32
#define WS_TOTALMAXFREEKBYTES 256
#define WS_MAXIMUMFASTALLOC (WS_MAXFREELISTS*WS_FREELISTSTEP)
#define WS_MAXFREEBYTES PerSlotMaxAlloc
static size_t PerSlotMaxAlloc=(WS_TOTALMAXFREEKBYTES*1024/WS_MAXFREELISTS);
static WStringProxy *FreeList=NULL;
static void **StringFreeList[WS_MAXFREELISTS];
static size_t StringFreeBytes[WS_MAXFREELISTS];
static bool InitManager=true;
static void InitManagerPointers()
{
memset(StringFreeList,0,sizeof(StringFreeList));
memset(StringFreeBytes,0,sizeof(StringFreeBytes));
InitManager=false;
}
static void *AllocStringBlock(size_t sz)
{
if (InitManager) InitManagerPointers();
if (sz>WS_MAXIMUMFASTALLOC) return malloc(sz);
int pos=(sz+WS_FREELISTSTEP-1)/WS_FREELISTSTEP;
void **nxt=StringFreeList[pos];
if (nxt==0)
{
printf("malloc %d\n",pos*WS_FREELISTSTEP);
return malloc(pos*WS_FREELISTSTEP);
}
printf("fast_alloc %d\n",pos*WS_FREELISTSTEP);
StringFreeList[pos]=(void **)(*nxt);
StringFreeBytes[pos]-=_msize(nxt);
return nxt;
}
static void DeallocStringBlock(void *ptr)
{
size_t sz=_msize(ptr);
if (sz>WS_MAXIMUMFASTALLOC) {free(ptr);return;}
int pos=(sz+WS_FREELISTSTEP-1)/WS_FREELISTSTEP;
if (sz+StringFreeBytes[pos]>WS_MAXFREEBYTES)
{
printf("free %d\n",sz);
free(ptr);return;
}
void **proxy=(void **)ptr;
*proxy=(void *)StringFreeList[pos];
StringFreeList[pos]=proxy;
StringFreeBytes[pos]+=sz;
printf("fast_free %d\n",sz);
}
static inline void *operator new(size_t alloc,size_t sz)
{
return AllocStringBlock(sz+alloc);
}
static inline void operator delete(void *p,size_t alloc)
{
DeallocStringBlock(p);
}
static inline void *operator new(size_t sz,void *ptr)
{
return ptr;
}
static inline void operator delete(void *ptr,void *p)
{
}
WStringProxy * WStringMemory::AllocString(const wchar_t *text, size_t size)
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
assert(size!=0 || text!=0);
if (size==0) size=wcslen(text);
WStringProxy *proxy=new((size+1)*sizeof(wchar_t)) WStringProxy(size,0,0);
wchar_t *alloctext=const_cast<wchar_t *>(proxy->GetStringFromMemBlock());
if (text) wcsncpy(alloctext,text,size);
alloctext[size]=0;
if (proxy->_redirect==0)
{
proxy->_redirect=alloctext;
proxy->_blockData2=1;
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return proxy;
}
WStringProxy * WStringMemory::AllocProxy(const WStringProxy &templateProxy)
{
WStringProxy * res;
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
if (FreeList==NULL) res=new WStringProxy(templateProxy);
else
{
WStringProxy *alloc=FreeList;
FreeList=alloc->_baseString;
res=new((void *)alloc) WStringProxy(templateProxy);
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return res;
}
void WStringMemory::FreeProxy(WStringProxy *proxy)
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
if (proxy->_operation==proxy->OpMemBlck && !(proxy->_blockData2==0 && proxy->_redirect!=NULL))
{
if (proxy->_blockData2==2) UnshareString(proxy);
DeallocStringBlock(proxy);
}
else
{
proxy->~WStringProxy();
proxy->_baseString=FreeList;
FreeList=proxy;
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
}
#ifdef WSTRING_MT
void WStringMemory::LockProxy( WStringProxy *proxy)
{
nextTry:
EnterCriticalSection(&GLocker);
WStringMTLock srch(proxy),*found;
if (GLockDB==NULL) GLockDB=new BTree<WStringMTLock>(16);
found=GLockDB->Find(srch);
if (found==NULL)
{
srch._event=NULL;
srch._owner=GetCurrentThreadId();
srch._recursionCount=1;
GLockDB->Add(srch);
}
else
{
if (found->_owner!=GetCurrentThreadId())
{
HANDLE w=found->_event;
if (w==0) {w=found->_event=CreateEvent(NULL,TRUE,FALSE,NULL);}
LeaveCriticalSection(&GLocker); //leave section
WaitForSingleObject(w,INFINITE);
goto nextTry;
}
else
{
found->_recursionCount++;
}
}
LeaveCriticalSection(&GLocker); //leave section
}
void WStringMemory::UnlockProxy( WStringProxy *proxy)
{
EnterCriticalSection(&GLocker);
WStringMTLock srch(proxy),*found;
found=GLockDB->Find(srch);
if (found)
{
if (--found->_recursionCount==0)
{
if (found->_event!=NULL)
{
SetEvent(found->_event);
CloseHandle(found->_event);
}
GLockDB->Remove(*found);
}
}
LeaveCriticalSection(&GLocker);
}
void WStringMemory::AddRefProxy(WStringProxy *proxy)
{
InterlockedIncrement(reinterpret_cast<LONG *>(&proxy->_refCount));
}
bool WStringMemory::ReleaseRefProxy(WStringProxy *proxy)
{
LONG res=InterlockedDecrement(reinterpret_cast<LONG *>(&proxy->_refCount));
if (res<0) res=InterlockedIncrement(reinterpret_cast<LONG *>(&proxy->_refCount));
return res==0;
}
#else
void WStringMemory::LockProxy( WStringProxy *proxy)
{
//not needed in single thread environment
}
void WStringMemory::UnlockProxy( WStringProxy *proxy)
{
//not needed in single thread environment
}
void WStringMemory::AddRefProxy(WStringProxy *proxy)
{
//no special handling in single thread environment
++proxy->_refCount;
}
bool WStringMemory::ReleaseRefProxy(WStringProxy *proxy)
{
//no special handling in single thread environment
if (proxy->_refCount) --proxy->_refCount;
return proxy->_refCount==0;
}
#endif
void WStringMemory::FreeExtra()
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
while (FreeList)
{
void *proxy=FreeList;
FreeList=FreeList->_baseString;
free(proxy);
}
for (int i=0;i<WS_MAXFREELISTS;i++)
{
while (StringFreeList[i])
{
void **proxy=StringFreeList[i];
StringFreeList[i]=(void **)(*proxy);
free(proxy);
}
StringFreeBytes[i]=0;
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
}
size_t WStringMemory::GetStatistics(size_t *details)
{
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
size_t sum=0;
for (int i=0;i<WS_MAXFREELISTS;i++)
{
sum+=StringFreeBytes[i];
if (details) details[i]=StringFreeBytes[i];
}
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return sum;
}
struct ShareDBItem
{
WStringProxy *_str;
ShareDBItem(WStringProxy *str=NULL):_str(str) {}
int Compare(const ShareDBItem& other) const
{
if (_str==NULL) return other._str!=NULL?1:0;
if (other._str==NULL) return -1;
return wcscmp(_str->_redirect,other._str->_redirect);
}
bool operator==(const ShareDBItem& other) const {return Compare(other)==0;}
bool operator>=(const ShareDBItem& other) const {return Compare(other)>=0;}
bool operator<=(const ShareDBItem& other) const {return Compare(other)<=0;}
bool operator!=(const ShareDBItem& other) const {return Compare(other)!=0;}
bool operator>(const ShareDBItem& other) const {return Compare(other)>0;}
bool operator<(const ShareDBItem& other) const {return Compare(other)<0;}
};
static BTree<ShareDBItem> *GDB=NULL;
WStringProxy *WStringMemory::ShareString(WStringProxy *proxy)
{
if (proxy->_operation!=WStringProxy::OpMemBlck || proxy->_blockData2==0 || proxy->_blockData2==2) return proxy;
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
if (GDB==NULL) GDB=new BTree<ShareDBItem>;
proxy->_blockData2=2; //block is subject of sharing
proxy->_redirect=proxy->GetStringFromMemBlock(); //setup pointer to string
ShareDBItem *found=GDB->Find(ShareDBItem(proxy));
if (found) {proxy->_blockData2=1;proxy=found->_str;}
else GDB->Add(ShareDBItem(proxy));
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
return proxy;
}
void WStringMemory::UnshareString(WStringProxy *proxy)
{
if (proxy->_operation!=WStringProxy::OpMemBlck || proxy->_blockData2!=2) return;
if (GDB==NULL) return;
#ifdef WSTRING_MT
EnterCriticalSection(&GLocker);
#endif
GDB->Remove(ShareDBItem(proxy));
proxy->_blockData2=1;
#ifdef WSTRING_MT
LeaveCriticalSection(&GLocker);
#endif
}

61
DDLReader/WStringMemory.h Normal file
View file

@ -0,0 +1,61 @@
// WStringMemory.h: interface for the WStringMemory class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WSTRINGMEMORY_H__79693029_4788_4099_9A97_92AF310A7AD5__INCLUDED_)
#define AFX_WSTRINGMEMORY_H__79693029_4788_4099_9A97_92AF310A7AD5__INCLUDED_
#include <WCHAR.H>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class WStringProxy;
class WStringMemory
{
public:
static WStringProxy * AllocString(const wchar_t *text, size_t size);
static WStringProxy * AllocProxy(const WStringProxy &templateProxy);
static void FreeProxy(WStringProxy *proxy);
static void LockProxy(WStringProxy *proxy);
static void UnlockProxy(WStringProxy *proxy);
//Releases extra memory leaved for future fast allocations
static void FreeExtra();
//Support addref for proxy - Single- or Multi- thread support
static void AddRefProxy(WStringProxy *proxy);
//Support addref for proxy - Single- or Multi- thread support
//returns true, when counter reached zero
static bool ReleaseRefProxy(WStringProxy *proxy);
///Gets statistics about memory manager
/**
@param details optional pointer to 32 size_t items. Array will be filled
with sizes of each string fastalloc group.
@return function returns total bytes allocated for string fast allocation.
(This number should be below 256KB)
*/
static size_t GetStatistics(size_t *details=NULL);
///Function allows sharing the strings
/** This function is called by WString::Share function
Function mark proxy shared. If string is same as shared,
it returns pointer to proxy with proxy of string that contains
the same text.
Read description of WString::Share for more informations
*/
static WStringProxy *ShareString(WStringProxy *proxy);
///Function disables sharing of the string
static void UnshareString(WStringProxy *proxy);
};
#endif // !defined(AFX_WSTRINGMEMORY_H__79693029_4788_4099_9A97_92AF310A7AD5__INCLUDED_)

185
DDLReader/WStringProxy.cpp Normal file
View file

@ -0,0 +1,185 @@
// WStringProxy.cpp: implementation of the WStringProxy class.
//
//////////////////////////////////////////////////////////////////////
#include "WStringProxy.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/** Funkce vytvoøí transitivní uzávìr.
to znamená, že zruší všechny zøetìzené redirecty.
*/
WStringProxy *WStringProxy::TransitivniUzaver()
{
if (_operation==OpSubstr && _offset==0 && _stringSize==_baseString->GetLength())
{
WStringProxy *next=_baseString->TransitivniUzaver();
if (next==NULL) return this;
next->AddRef();
_baseString->Release();
_baseString=next;
return next;
}
return NULL;
}
/** Main render procedure
It creates allocates buffer proxy and renders tree into it
Then turns self into redirect proxy a redirect self into newly created string
Rerurns pointer to newly created proxy
*/
WStringProxy *WStringProxy::RenderString()
{
if (_operation==OpMemBlck) return this;
WStringProxy *pp=TransitivniUzaver();
if (pp!=NULL) return pp->_baseString->RenderString();
WStringProxy *newProxy=WStringMemory::AllocString(NULL,_stringSize);
wchar_t *renderPtr=const_cast<wchar_t *>(newProxy->GetStringFromMemBlock());
RenderStringToBuffer(renderPtr);
newProxy->AddRef();
this->~WStringProxy();
_operation=OpSubstr;
_offset=0;
_baseString=newProxy;
return newProxy;
}
/** Function renders simple effect into buffer
Function needs buffer with nul terminated string
*/
void WStringProxy::RenderSimpleEffect(wchar_t *renderPtr)
{
assert(_operation==OpEffect);
switch (_effect)
{
case EfLower: wcslwr(renderPtr);break;
case EfUpper: wcsupr(renderPtr);break;
case EfReverse: wcsrev(renderPtr);break;
}
}
/** Light phase of rendering. Used to render string that is not
created from substring. This part is optimized for concat and user effects
When substring must be rendered, function call RenderStringToBufferSubstr to
render substring.
*/
void WStringProxy::RenderStringToBuffer(wchar_t *renderPtr)
{
WStringMemory::LockProxy(this);
switch (_operation)
{
case OpConcat:
_baseString->RenderStringToBuffer(renderPtr);
_secondString->RenderStringToBuffer(renderPtr+_baseString->GetLength());
break;
case OpSubstr:
{
_baseString->RenderStringToBufferSubstr(renderPtr,_offset,GetLength());
}
break;
case OpMemBlck:
{
const wchar_t *str=GetStringFromMemBlock();
wcsncpy(renderPtr,str,_stringSize);
}
break;
case OpEffect:
{
unsigned long offset=0;
renderPtr[_stringSize]=0; //we can append zero, because right side of string is not yet rendered
//if this is end of string, one extra character for zero is also allocated.
//efect functions can rely on it.
if (_blockData2>=256) offset=_userEffect->PreRenderString(renderPtr,_baseString->GetLength()); //call prerender to prepare begin of buffer
_baseString->RenderStringToBuffer(renderPtr+offset); //render string to rest of buffer
if (_blockData2>=256) _userEffect->RenderString(renderPtr,_baseString->GetLength()); //apply effect to buffer
else RenderSimpleEffect(renderPtr);
}
break;
};
WStringMemory::UnlockProxy(this);
}
/**
Deep phase of rendering. Function can render substrings, or render substring of two
concated strings. Function can also perform partial effect on string. Function cannot
handle partial user effect, so this effects are converted to things strings.
*/
void WStringProxy::RenderStringToBufferSubstr(wchar_t *renderPtr, size_t offset, size_t size)
{
WStringMemory::LockProxy(this);
switch (_operation)
{
case OpConcat:
{
//process substring of concat
//count characters in buffer
size_t rendered;
//when string starts in left string
if (_baseString->GetLength()>offset)
{
//calculate total characters that may be rendered
rendered=_baseString->GetLength()-offset;
//but limit it to request size
if (rendered>size) rendered=size;
//render substring into buffer
_baseString->RenderStringToBufferSubstr(renderPtr,offset,rendered);
}
else
//no character has been rendered
rendered=0;
//there is still characters remained to render. We will take it from second string
if (size-rendered>0)
{
if (offset>_baseString->GetLength()) offset-=_baseString->GetLength();
else offset=0;
_secondString->RenderStringToBufferSubstr(renderPtr+rendered,offset,size-rendered);
}
}
break;
case OpSubstr:
{ //rendering substrings is very easy
offset+=_offset; //add offset of substring
assert(offset+size<=GetLength()); //check length
//render substring
this->RenderStringToBufferSubstr(renderPtr,offset,size);
}
break;
case OpMemBlck:
{
//rendering from memory, final stop in recursion
//Get pointer string
const wchar_t *str=GetStringFromMemBlock();
//copy substring from string into render buffer
wcsncpy(renderPtr,str+offset,size);
}
break;
case OpEffect:
if (_blockData2>=256) //interface cannot handle partial rendering
{
RenderString(); //convert proxy to simple redirect and render it
RenderStringToBufferSubstr(renderPtr,offset,size); //now we are able to cut out part
}
else
{
//all standard effects maps string 1:1
//first get content of substring into buffer
_baseString->RenderStringToBufferSubstr(renderPtr,offset,size);
//we can append zero, because right side of string is not yet rendered
renderPtr[size]=0;
//process effect on target
RenderSimpleEffect(renderPtr);
}
break;
};
WStringMemory::UnlockProxy(this);
}

232
DDLReader/WStringProxy.h Normal file
View file

@ -0,0 +1,232 @@
// WStringProxy.h: interface for the WStringProxy class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_WSTRINGPROXY_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_)
#define AFX_WSTRINGPROXY_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "WStringMemory.h"
#include "IWStringEffect.h"
#include <WCHAR.H>
#include <string.h>
#include <assert.h>
#include <malloc.h>
/*
List of proxy types
Memory_Proxy _operation=OpMemBlck
_blockData==0 and _blockData2==0
or
_blockData!=0 and _blockData2!=0
(_redirect - debug pointer)
(_blockData - 1)
Proxy_Const _operation=OpMemBlck
_redirect - pointer to string
_blockData2=0
Proxy_Shared _operation=OpMemBlck
_redirect - pointer to string
_blockData2=2;
Proxy_Immediate _operation=OpMemBlck
_blockData>0xFFFF
_blockData2>0xFFFF
both parameters are used by immediate memory manager
Proxy_Concat _operation=OpConcat
_baseString and _secondString is valid
Proxy_Link _operation=OpSubstr
_baseString is valid
_stringSize==_baseString->_stringSize
_offset==0;
NOTE: Can be used without rendering
Proxy_RightSub _operation=OpSubstr
_baseString is valid
_offset<=_baseString->_stringSize
_stringSize==_baseString->_stringSize-_offset
NOTE: Can be used without rendering
Proxy_SubString _operation=OpSubstr
_baseString is valid
_offset<=_baseString->_stringSize
_stringSize<=_baseString->_stringSize-_offset
Proxy_Effect _operation=OpEffect
_baseString is valid
_stringSize=_baseString->_stringSize
_effect defining effect code < 0xFFFF
Proxy_UserEffect _operation=OpEffect
_baseString is valid
_stringSize=_baseString->_stringSize
_effect>0xFFFF
_userEffect defining pointer to effect interface
*/
class WStringProxy
{
public:
enum Operation
{
OpConcat=0, //proxy contains two links to concat it
OpSubstr=1, //proxy contains link to another proxy and specified substring
OpMemBlck=-2, //proxy contains informations about following string
OpEffect=-1, //proxy describing some efect with string
};
enum Effect
{
EfLower, //effect lower case
EfUpper, //effect upper case
EfReverse, //effect reverse string
};
public:
unsigned long _refCount; //reference count
unsigned long _stringSize:30; //string size in characters (maximum size 1073741823 characters ~ 2147483646 bytes)
Operation _operation:2; //operation with string or proxy type
union
{
WStringProxy *_baseString; //pointer to next proxy referenced by this proxy
unsigned long _blockData; //user defined block data for OpMemBlock proxy type
const wchar_t *_redirect; //used for OpMemBlock, when _blockData2 is zero.
};
union
{
WStringProxy *_secondString; //pointer to second string for OpConcat
unsigned long _offset; //offset of substring for OpSubstr
Effect _effect; //effect selector for OpEffect
IWStringEffect *_userEffect; //user effect defined by IWStringEffect interface (valid when _effect is invalid)
unsigned long _blockData2; //user defined block data for OpMemBlock proxy type - exception: if this value is zero, member _redirect is valid
};
void RenderStringToBuffer(wchar_t *renderPtr);
void RenderStringToBufferSubstr(wchar_t *renderPtr, size_t offset, size_t size);
WStringProxy *TransitivniUzaver();
void RenderSimpleEffect(wchar_t *renderPtr);
public:
WStringProxy():_refCount(0),_operation(OpSubstr),_stringSize(0),_baseString(0),_secondString(0) {} //inicializes empty string proxy
WStringProxy(WStringProxy *other):
_refCount(0),
_stringSize(other->GetLength()),
_baseString(other),
_operation(OpSubstr),
_offset(0)
{_baseString->AddRef();}
WStringProxy(WStringProxy *other, unsigned long offset, unsigned long size):
_refCount(0),
_stringSize(size),
_baseString(other),
_operation(OpSubstr),
_offset(offset)
{_baseString->AddRef();}
WStringProxy(WStringProxy *a, WStringProxy *b):
_refCount(0),
_stringSize(a->GetLength()+b->GetLength()),
_baseString(a),
_operation(OpConcat),
_secondString(b)
{_baseString->AddRef();_secondString->AddRef();}
WStringProxy(WStringProxy *a, Effect effect):
_refCount(0),
_stringSize(a->GetLength()),
_baseString(a),
_operation(OpEffect),
_effect(effect)
{_baseString->AddRef();}
WStringProxy(WStringProxy *a, IWStringEffect *userEffect):
_refCount(0),
_stringSize(a->GetLength()+userEffect->GetEffectExtraSize(a->GetLength())),
_baseString(a),
_operation(OpEffect),
_userEffect(userEffect)
{_baseString->AddRef();}
WStringProxy(unsigned long size, unsigned long user1, unsigned long user2):
_refCount(0),
_stringSize(size),
_operation(OpMemBlck),
_blockData(user1),
_blockData2(user2)
{}
WStringProxy(const wchar_t *imText):
_refCount(0),
_stringSize(wcslen(imText)),
_redirect(imText),
_blockData2(0),
_operation(OpMemBlck)
{}
WStringProxy(const WStringProxy &other)
{
memcpy(this,&other,sizeof(*this));
if (_operation!=OpMemBlck) _baseString->AddRef();
if (_operation==OpConcat) _secondString->AddRef();
}
WStringProxy& operator=(const WStringProxy &other)
{
WStringProxy::~WStringProxy(); //call destructor to destruct current proxy
memcpy(this,&other,sizeof(*this)); //construct new proxy from template
if (_operation!=OpMemBlck) _baseString->AddRef();
if (_operation==OpConcat) _secondString->AddRef();
}
WStringProxy *RenderString();
~WStringProxy()
{
if (_operation!=OpMemBlck) _baseString->Release();
if (_operation==OpConcat) _secondString->Release();
}
unsigned long GetLength() {return _stringSize;}
void AddRef() {if (this) WStringMemory::AddRefProxy(this);}
void Release() {if (this) if (WStringMemory::ReleaseRefProxy(this)) WStringMemory::FreeProxy(this);}
const wchar_t *GetString()
{
if (_operation==OpMemBlck) return (const wchar_t *)(this+1);
WStringProxy *p=RenderString();
(*this)=*p;
return (const wchar_t *)(p+1);
}
const wchar_t *GetStringFromMemBlock()
{
assert(_operation==OpMemBlck);
if (_blockData2==0 && _redirect!=NULL) return _redirect;
else return (const wchar_t *)(this+1);
}
bool IsShared() {return _refCount>1;}
void RecalcLength()
{
const wchar_t *str=GetStringFromMemBlock();
_stringSize=wcslen(str);
}
};
#endif // !defined(AFX_WSTRINGPROXY_H__863ADE82_7789_4E54_BE7D_B8F0740FD81B__INCLUDED_)

BIN
DDLReader/res/DDLReader.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,13 @@
//
// DDLREADER.RC2 - resources Microsoft Visual C++ does not edit directly
//
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...
/////////////////////////////////////////////////////////////////////////////

49
DDLReader/resource.h Normal file
View file

@ -0,0 +1,49 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by DDLReader.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_DDLREADER_DIALOG 102
#define IDS_FILEOPENFAILED 102
#define IDC_HEADGROUP 103
#define IDC_HEADFNAME 104
#define IDC_HEADSIZE 105
#define IDC_HEADOFFSET 106
#define IDS_DDLFILTER 107
#define IDC_GROUP_GRAPHICS 108
#define IDC_GROUP_SOUNDS 109
#define IDC_GROUP_FONTS 110
#define IDC_GROUP_BASIC 111
#define IDC_GROUP_ITEMS 112
#define IDC_GROUP_MONSTERS 113
#define IDC_GROUP_DIALOGS 114
#define IDC_GROUP_UNSPECIFIED 115
#define IDC_GROUP_UNKNOWN 116
#define IDS_UNABLETOCREATEFILE 117
#define IDS_UNABLETOEXTACTDATA 118
#define IDR_MAINFRAME 128
#define IDD_PROGRESS 129
#define IDD_EXPORTING 129
#define IDC_FILELIST 1001
#define IDC_FOLDER 1002
#define IDC_BROWSE 1003
#define IDC_EXPORT 1004
#define IDC_POPISEK 1005
#define IDC_DDLFILE 1006
#define IDC_DDLBROWSE 1007
#define IDC_PROGRESS 1008
#define IDC_NAME 1009
#define IDC_BUTTON1 1010
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1011
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

BIN
FONT/BIG.FON Normal file

Binary file not shown.

BIN
FONT/BIG2.FON Normal file

Binary file not shown.

BIN
FONT/BOLDCZ.FON Normal file

Binary file not shown.

BIN
FONT/BROOKLIN.FON Normal file

Binary file not shown.

BIN
FONT/EUROMODE.FON Normal file

Binary file not shown.

BIN
FONT/FONT4X8.FON Normal file

Binary file not shown.

BIN
FONT/FONT5X8.FON Normal file

Binary file not shown.

BIN
FONT/FONT6X9.FON Normal file

Binary file not shown.

BIN
FONT/IKONES.FON Normal file

Binary file not shown.

BIN
FONT/KNIHA.FON Normal file

Binary file not shown.

BIN
FONT/SADA16.FON Normal file

Binary file not shown.

BIN
FONT/SADA7.FON Normal file

Binary file not shown.

BIN
FONT/TIMESBIG.FON Normal file

Binary file not shown.

BIN
FONT/TIMESBIT.FON Normal file

Binary file not shown.

BIN
FONT/TIMESE.FON Normal file

Binary file not shown.

BIN
FONT/TINY.FON Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show more