1 // UnmasswDlg.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "Unmassw.h"
6 #include "UnmasswDlg.h"
7 #include "UnmassAboutDlg.h"
8 #include "ChArchType.h"
9 
10 #include "utools.h"
11 
12 #include <direct.h>
13 #include <assert.h>
14 #include <process.h>
15 #include <stdio.h>
16 #include <io.h>
17 
18 #ifdef _DEBUG
19 #define new DEBUG_NEW
20 #undef THIS_FILE
21 static char THIS_FILE[] = __FILE__;
22 #endif
23 
24 /////////////////////////////////////////////////////////////////////////////
25 // CUnmasswDlg dialog
26 
27 
CUnmasswDlg(CWnd * pParent)28 CUnmasswDlg::CUnmasswDlg(CWnd* pParent /*=NULL*/)
29 	: CDialog(CUnmasswDlg::IDD, pParent)
30 {
31 	//{{AFX_DATA_INIT(CUnmasswDlg)
32 	m_info = _T("");
33 	m_info2 = _T("");
34 	//}}AFX_DATA_INIT
35 }
36 
DoDataExchange(CDataExchange * pDX)37 void CUnmasswDlg::DoDataExchange(CDataExchange* pDX)
38 {
39 	CDialog::DoDataExchange(pDX);
40 	//{{AFX_DATA_MAP(CUnmasswDlg)
41 	DDX_Control(pDX, IDC_COMBOselTypes, m_SelTypes);
42 	DDX_Control(pDX, IDC_PROGRESS1, m_progress);
43 	DDX_Control(pDX, IDC_BUTTONdir, m_DirButton);
44 	DDX_Control(pDX, IDC_LISTfiles, m_list);
45 	DDX_Text(pDX, IDC_STATICinfo, m_info);
46 	DDX_Text(pDX, IDC_STATICinfo2, m_info2);
47 	//}}AFX_DATA_MAP
48 }
49 
BEGIN_MESSAGE_MAP(CUnmasswDlg,CDialog)50 BEGIN_MESSAGE_MAP(CUnmasswDlg, CDialog)
51 	//{{AFX_MSG_MAP(CUnmasswDlg)
52 	ON_WM_PAINT()
53 	ON_WM_QUERYDRAGICON()
54 	ON_BN_CLICKED(IDC_BUTTONopen, OnBUTTONopen)
55 	ON_BN_CLICKED(IDC_BUTTONextract, OnBUTTONextract)
56 	ON_BN_CLICKED(IDC_BUTTONdir, OnBUTTONdir)
57 	ON_WM_DESTROY()
58 	ON_BN_CLICKED(IDC_BUTTONabout, OnBUTTONabout)
59 	ON_NOTIFY(LVN_COLUMNCLICK, IDC_LISTfiles, OnColumnclickLISTfiles)
60 	ON_WM_SIZE()
61 	ON_WM_CREATE()
62 	ON_NOTIFY(NM_DBLCLK, IDC_LISTfiles, OnDblclkLISTfiles)
63 	ON_BN_CLICKED(IDC_BUTTONselAdd, OnBUTTONselAdd)
64 	ON_BN_CLICKED(IDC_BUTTONselRem, OnBUTTONselRem)
65 	ON_BN_CLICKED(IDC_BUTTONaddFile, OnBUTTONaddFile)
66 	ON_BN_CLICKED(IDC_BUTTONaddDir, OnBUTTONaddDir)
67 	ON_BN_CLICKED(IDC_BUTTONunlinkFile, OnBUTTONunlinkFile)
68 	ON_BN_CLICKED(IDC_BUTTONdelFile, OnBUTTONdelFile)
69 	ON_BN_CLICKED(IDC_BUTTONcreateArchive, OnBUTTONcreateArchive)
70 	ON_WM_CLOSE()
71 	//}}AFX_MSG_MAP
72 END_MESSAGE_MAP()
73 
74 /////////////////////////////////////////////////////////////////////////////
75 // CUnmasswDlg message handlers
76 
77 #define BUTTON_OPEN_STRING "&Open .."
78 #define BUTTON_CLOSE_STRING "C&lose"
79 
80 BOOL CUnmasswDlg::OnInitDialog()
81 {
82 	CDialog::OnInitDialog();
83 
84 	icon = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDR_MAINFRAME ) );
85 	SetIcon( icon, true );		// Set big icon
86 	SetIcon( icon, false );		// Set small icon
87 
88 
89 	ArchiveOpened = 0;
90 
91 	int		i;
92 
93 	GetModuleFileName( NULL, ProgramPath, 512 );
94 	i = strlen( ProgramPath ) - 1;
95 	while (( ProgramPath[ i ] != '\\' ) && ( ProgramPath[ i ] != '/' ))
96 		i--;
97 	ProgramPath[ i ] = 0;
98 
99 	strcpy( TempDir, ProgramPath );
100 	strcat( TempDir, "\\TEMP" );
101 
102 	// ======== init =====
103 	m_list.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
104 
105 	m_list.InsertColumn( 0, "#", LVCFMT_LEFT, 40 );
106 	m_list.InsertColumn( 1, "file", LVCFMT_LEFT, 280 );
107 	m_list.InsertColumn( 2, "size", LVCFMT_LEFT, 70 );
108 	m_list.InsertColumn( 3, "type", LVCFMT_LEFT, 50 );
109 
110 	FileInfo = NULL;
111 //	FileInfo.SetVariableSize( sizeof( CMassArchive::s_FileRec ) );
112 	InListPos = NULL;
113 
114 	m_progress.ShowWindow( false );
115 	m_progress.SetRange( 0, 100 );
116 	m_progress.SetPos( 23 );
117 
118 	SetWindowText( NAME_VER );
119 
120 	m_info = NAME_VER" created by Mirex";
121 
122 	getcwd( OutputDir, MaxPathLength );
123 	strcpy( OpenDir, OutputDir );
124 
125 	sort_displayed = sort_undefined;
126 
127 	InitWndPositions();
128 
129 	UpdateData( false );
130 	return TRUE;  // return TRUE  unless you set the focus to a control
131 }
132 
133 // If you add a minimize button to your dialog, you will need the code below
134 //  to draw the icon.  For MFC applications using the document/view model,
135 //  this is automatically done for you by the framework.
136 
OnPaint()137 void CUnmasswDlg::OnPaint()
138 {
139 	if (IsIconic())
140 	{
141 		CPaintDC dc(this); // device context for painting
142 
143 		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
144 
145 		// Center icon in client rectangle
146 		int cxIcon = GetSystemMetrics(SM_CXICON);
147 		int cyIcon = GetSystemMetrics(SM_CYICON);
148 		CRect rect;
149 		GetClientRect(&rect);
150 		int x = (rect.Width() - cxIcon + 1) / 2;
151 		int y = (rect.Height() - cyIcon + 1) / 2;
152 
153 		// Draw the icon
154 		dc.DrawIcon(x, y, icon);
155 	}
156 	else
157 	{
158 		CDialog::OnPaint();
159 	}
160 }
161 
OnQueryDragIcon()162 HCURSOR CUnmasswDlg::OnQueryDragIcon()
163 {
164 	return (HCURSOR) icon;
165 }
166 
OnBUTTONopen()167 void CUnmasswDlg::OnBUTTONopen()
168 {
169 	unsigned long	l, i, j;
170 	CString			filter, cstr, cstr2, ext;
171 	int				res;
172 
173 	//ak je otvoreny tak close
174 	if ( ArchiveOpened == 1 ) {
175 
176 		CloseArchive();
177 
178 	}
179 
180 	chdir( OpenDir );
181 
182 	filter = "All files *.*|*.*|";
183 	for( i=0; i<mass.massftypes_count; i++ ) {
184 		cstr.Format( "%s|", mass.GetTypeIdentString( i ) );
185 
186 		//GetTypeExt moze vratit aj viac pripon, musim po jednom pridat
187 		ext = mass.GetTypeExt( i );
188 		j = l = 0;
189 		while ( true ) {
190 			while (( l < ext.GetLength() ) && ( ext.GetAt( l ) != ',' ))
191 				l++;
192 			cstr2.Format( "*.%s", ext.Mid( j, l - j ) );
193 			cstr += cstr2;
194 
195 			if ( l == ext.GetLength() )
196 				break;
197 			else
198 				cstr += "; ";
199 			j = l + 1;
200 			l = j;
201 		} ;
202 
203 		cstr += "|";
204 
205 		filter += cstr;
206 	}
207 
208 	filter += "||";
209 
210 	CFileDialog		dlg( true, NULL, NULL, 0, filter, this );
211 
212 	if ( dlg.DoModal() == IDOK ) {
213 
214 		CloseArchive();
215 
216 		OpenArchive( dlg.GetPathName().GetBuffer(0) );
217 
218 	}
219 }
220 
OnBUTTONextract()221 void CUnmasswDlg::OnBUTTONextract()
222 {
223 	POSITION		pos = m_list.GetFirstSelectedItemPosition();
224 	int				nItem;
225 	unsigned long	count = 0, files;
226 
227 	files = m_list.GetSelectedCount();
228 
229 	if ( files == 0 ) {
230 		m_info = "No files selected";
231 		UpdateData( false );
232 		return;
233 	}
234 
235 	GetDlgItem( IDC_STATICinfo )->ShowWindow( false );
236 	m_progress.ShowWindow( true );
237 	m_progress.SetPos( 0 );
238 	UpdateData( false );
239 
240 	while ( pos != NULL ) {
241 
242 		nItem = InListPos[ m_list.GetNextSelectedItem(pos) ];
243 
244 		memcpy( &mass.FileRec, &FileInfo[nItem].FileRec, sizeof( CMassArchive::s_FileRec ) );
245 		sprintf( mass.FileRec.name, "%s\\%s",
246 			OutputPath.GetBuffer(0), FileInfo[nItem].FileRec.name );
247 
248 /*		mass.FileRec.offset = FileInfo[ nItem ].FileRec.offset;
249 		mass.FileRec.size = FileInfo[ nItem ].FileRec.size;
250 		mass.FileRec.flag = FileInfo[ nItem ].FileRec.flag;
251 		strcpy( mass.FileRec.type, FileInfo[ nItem ].FileRec.type );
252 */
253 		if ( mass.Extract() == 0 ) {
254 			MessageBox( mass.GetErrorStr() );
255 			break;
256 		}
257 
258 		count++;
259 
260 		m_progress.SetPos( count*100 / files );
261 		UpdateData( false );
262 	} ;
263 
264 	m_progress.ShowWindow( false );
265 	GetDlgItem( IDC_STATICinfo )->ShowWindow( true );
266 	m_info.Format( "%lu files extracted. Stopped at file #%lu", count, nItem );
267 	UpdateData( false );
268 }
269 
OnBUTTONdir()270 void CUnmasswDlg::OnBUTTONdir()
271 {
272 	CFileDialog		dlg( true, NULL, "this one", OFN_NOVALIDATE, "Choose output directory|mirex rules!||", this );
273 	CString			path;
274 	int				pos;
275 
276 	chdir( OutputDir );
277 
278 	if ( dlg.DoModal() == IDOK ) {
279 
280 		getcwd( OutputDir, MaxPathLength );
281 
282 		path = dlg.GetPathName();
283 
284 		pos = path.ReverseFind( '\\' );
285 		if ( pos == -1 )
286 			return;
287 
288 		path.Delete( pos, path.GetLength() - pos );
289 
290 		m_DirButton.SetWindowText( path.GetBuffer(0) );
291 
292 		OutputPath = path;
293 	}
294 
295 	m_list.SetFocus();
296 }
297 
298 
OnDestroy()299 void CUnmasswDlg::OnDestroy()
300 {
301 	int			res, findh;
302 	_finddata_t	find;
303 	char		str[ 512 ];
304 
305 	CDialog::OnDestroy();
306 
307 	m_info = "Deleting temp files";
308 	UpdateData( false );
309 
310 	//find all temp files and delete them !
311 	sprintf( str, "%s\\*.*", TempDir );
312 	res = findh = _findfirst( str, &find );
313 
314 	while ( res != -1 ) {
315 
316 		if (( strcmp( find.name, "." ) != 0 ) && ( strcmp( find.name, ".." ) != 0 )) {
317 			sprintf( str, "%s\\%s", TempDir, find.name );
318 			remove( str );
319 		}
320 
321 		res = _findnext( findh, &find );
322 	}
323 
324 	_findclose( findh );
325 
326 	CloseArchive();
327 
328 }
329 
OnBUTTONabout()330 void CUnmasswDlg::OnBUTTONabout()
331 {
332 	CUnmassAboutDlg	dlg;
333 
334 	dlg.DoModal();
335 
336 }
337 
OnColumnclickLISTfiles(NMHDR * pNMHDR,LRESULT * pResult)338 void CUnmasswDlg::OnColumnclickLISTfiles(NMHDR* pNMHDR, LRESULT* pResult)
339 {
340 	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
341 
342 	switch ( pNMListView->iSubItem ) {
343 	case 0: sort = sort_unsorted; break;
344 	case 1:	sort = sort_name; break;
345 	case 2:	sort = sort_size; break;
346 	case 3:	sort = sort_type; break;
347 	default:
348 		assert( false );
349 		break;
350 	}
351 
352 	FillListSorted( sort );
353 
354 	*pResult = 0;
355 }
356 
357 //ak je uz list zobrazeny, tak idem po jeho poradi. hodi sa tak, ze ked zosortujes
358 //podla size a potom podla type, tak budes mat zoradene podla typu a tiez podla size
FillListSorted(e_sort sorttype)359 void CUnmasswDlg::FillListSorted( e_sort sorttype )
360 {
361 	unsigned long		i, it, j, p, size;
362 //	CDWordArray			sorted;
363 //	int					filled;
364 	char				str[ 256 ],
365 						name[ CMassArchive::FileNameWithPathMaxLen ],
366 						type[ CMassArchive::TypeMaxLen ];
367 //	CString				cstr;
368 
369 	if ( sort_displayed == sorttype )
370 		return;
371 
372 	UpdateData( );
373 	m_progress.ShowWindow( true );
374 	m_info = "Sorting...";
375 	UpdateData( false );
376 
377 	if ( sorttype == sort_unsorted )
378 		for( i=0; i<mass.MassfInfo.files_count; i++ )
379 			InListPos[ i ] = i;
380 	else
381 		for( i=0; i<mass.MassfInfo.files_count; i++ ) {
382 
383 //			cstr = "";
384 			name[0] = 127; type[0] = 127; size = MAXLONG;
385 
386 			it = -1;
387 			//musim najst ktory zaznam sem vlozim podla kriteria
388 			for( j=i; j<mass.MassfInfo.files_count; j++ ) {
389 				switch( sorttype ) {
390 				case sort_name:
391 //					if ( cstr.CompareNoCase( FileInfo[ InListPos[ j ] ].FileRec.name ) < 0 ) {
392 					if ( UnmassTools::_strcasecmp( FileInfo[ InListPos[ j ] ].FileRec.name, name ) < 0 ) {
393 						it = j;
394 //						cstr = FileInfo[ InListPos[ j ] ].FileRec.name;
395 						strcpy( name, FileInfo[ InListPos[ j ] ].FileRec.name );
396 					}
397 					break;
398 				case sort_size:
399 					if ( FileInfo[ InListPos[ j ] ].FileRec.size < size ) {
400 						it = j;
401 						size = FileInfo[ InListPos[ j ] ].FileRec.size;
402 					}
403 					break;
404 				case sort_type:
405 //					if ( cstr.CompareNoCase( FileInfo[ InListPos[ j ] ].FileRec.type ) < 0 ) {
406 					if ( UnmassTools::_strcasecmp( FileInfo[ InListPos[ j ] ].FileRec.type, type ) < 0 ) {
407 						it = j;
408 //						cstr = FileInfo[ InListPos[ j ] ].FileRec.type;
409 						strcpy( type, FileInfo[ InListPos[ j ] ].FileRec.type );
410 					}
411 					break;
412 				default:
413 					assert( false );
414 					break;
415 				}//switch sorttype
416 			}
417 
418 			assert( it != -1 );
419 
420 			//takze mam poziciu itemu v InListPos. musim ho dat na poziciu i, a ostatne
421 			// posunut
422 
423 			p = InListPos[ it ];
424 			for( j=it; j>i; j-- )
425 				InListPos[ j ] = InListPos[ j-1 ];
426 
427 			InListPos[ i ] = p;
428 
429 			//zobrazim progress
430 			if ( (i+1) % 500 == 0 ) {
431 				m_progress.SetPos( i * 100 / mass.MassfInfo.files_count );
432 				UpdateData( false );
433 			}
434 
435 		}
436 
437 	m_info = "Purging list";
438 	UpdateData( false );
439 
440 	m_list.DeleteAllItems();
441 
442 	m_info = "Displaying";
443 	UpdateData( false );
444 
445 	for( i=0; i<mass.MassfInfo.files_count; i++ ) {
446 
447 		it = InListPos[ i ];
448 
449 		sprintf( str, "%lu", it );
450 		m_list.InsertItem( i, str );
451 		m_list.SetItemText( i, 1, FileInfo[ it ].FileRec.name );
452 		sprintf( str, "%lu", FileInfo[ it ].FileRec.size );
453 		m_list.SetItemText( i, 2, str );
454 		m_list.SetItemText( i, 3, FileInfo[ it ].FileRec.type );
455 
456 		if ( (i+1) % 500 == 0 ) {
457 			m_progress.SetPos( i * 100 / mass.MassfInfo.files_count );
458 			UpdateData( false );
459 		}
460 
461 	}
462 
463 	m_progress.ShowWindow( false );
464 
465 	m_info = "";
466 	UpdateData( false );
467 
468 	sort_displayed = sorttype;
469 }
470 
471 // ======= window sizing ========
OnSize(UINT nType,int cx,int cy)472 void CUnmasswDlg::OnSize(UINT nType, int cx, int cy)
473 {
474 	CDialog::OnSize(nType, cx, cy);
475 
476 	SizeCtrls.Size();
477 
478 	RedrawWindow();
479 }
480 
InitWndPositions(void)481 void CUnmasswDlg::InitWndPositions( void )
482 {
483 	SizeCtrls.SetWindow( this );
484 
485 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONopen,
486 		top_left, top_left, right_bottom, right_bottom );
487 
488 	SizeCtrls.SetWndEdgeAssignment( IDC_STATICinfo2,
489 		top_left, right_bottom, top_left, top_left );
490 
491 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONabout,
492 		right_bottom, right_bottom, top_left, top_left );
493 
494 	SizeCtrls.SetWndEdgeAssignment( IDC_LISTfiles,
495 		top_left, right_bottom, top_left, right_bottom );
496 
497 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONextract,
498 		top_left, top_left, right_bottom, right_bottom );
499 
500 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONaddFile,
501 		top_left, top_left, right_bottom, right_bottom );
502 
503 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONaddDir,
504 		top_left, top_left, right_bottom, right_bottom );
505 
506 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONunlinkFile,
507 		top_left, top_left, right_bottom, right_bottom );
508 
509 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONdelFile,
510 		top_left, top_left, right_bottom, right_bottom );
511 
512 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONcreateArchive,
513 		right_bottom, right_bottom, right_bottom, right_bottom );
514 
515 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONdir,
516 		top_left, right_bottom, right_bottom, right_bottom );
517 
518 	SizeCtrls.SetWndEdgeAssignment( IDC_STATICinfo,
519 		top_left, right_bottom, right_bottom, right_bottom );
520 
521 	SizeCtrls.SetWndEdgeAssignment( IDC_PROGRESS1,
522 		top_left, right_bottom, right_bottom, right_bottom );
523 	//type selection: combo, add, remove
524 	SizeCtrls.SetWndEdgeAssignment( IDC_COMBOselTypes,
525 		right_bottom, right_bottom, top_left, top_left );
526 
527 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONselAdd,
528 		right_bottom, right_bottom, top_left, top_left );
529 
530 	SizeCtrls.SetWndEdgeAssignment( IDC_BUTTONselRem,
531 		right_bottom, right_bottom, top_left, top_left );
532 
533 
534 /*	GetDlgItem( IDC_BUTTONopen )->GetWindowRect( &rct );
535 	SetMyWindowPosition( wnd_ButtonOpen, IDC_BUTTONopen,
536 		rct.left, top_left, rct.right, top_left,
537 		rct.top, top_left, rct.bottom, top_left );
538 
539 	GetDlgItem( IDC_STATICinfo2 )->GetWindowRect( &rct );
540 	SetMyWindowPosition( wnd_info2, IDC_STATICinfo2,
541 		rct.left, top_left, mainrct.right - rct.right, right_bottom,
542 		rct.top, top_left, rct.bottom, top_left );
543 
544 	GetDlgItem( IDC_BUTTONabout )->GetWindowRect( &rct );
545 	SetMyWindowPosition( wnd_ButtonAbout, IDC_BUTTONabout,
546 		mainrct.right - rct.left, right_bottom, mainrct.right - rct.right, right_bottom,
547 		rct.top, top_left, rct.bottom, top_left );
548 
549 	GetDlgItem( IDC_LISTfiles )->GetWindowRect( &rct );
550 	SetMyWindowPosition( wnd_list, IDC_LISTfiles,
551 		rct.left, top_left, mainrct.right - rct.right, right_bottom,
552 		rct.top, top_left, mainrct.bottom - rct.bottom, right_bottom );
553 
554 	GetDlgItem( IDC_BUTTONextract )->GetWindowRect( &rct );
555 	SetMyWindowPosition( wnd_ButtonExtract, IDC_BUTTONextract,
556 		rct.left, top_left, rct.right, top_left,
557 		mainrct.bottom - rct.top, right_bottom, mainrct.bottom - rct.bottom, right_bottom );
558 
559 	GetDlgItem( IDC_BUTTONdir )->GetWindowRect( &rct );
560 //	SetMyWindowPosition( wnd_ButtonOutDir, IDC_BUTTONdir,
561 //		rct.left, top_left, mainrct rct.right, right_bottom,
562 //		mainrct.bottom - rct.top, right_bottom, mainrct.bottom - rct.bottom, right_bottom );
563 
564 	SetWindowEdgeAssignment( wnd_ButtonOutDir, IDC_BUTTONdir,
565 		top_left, right_bottom, right_bottom, right_bottom );
566 
567 	SetWindowEdgeAssignment( wnd_info, IDC_STATICinfo,
568 		top_left, right_bottom, right_bottom, right_bottom );
569 
570 	SetWindowEdgeAssignment( wnd_progress, IDC_PROGRESS1,
571 		top_left, right_bottom, right_bottom, right_bottom );
572 
573 	WndDataInitialized = 1;
574 */
575 }
576 
577 // ======= window sizing END ========
578 
OnCreate(LPCREATESTRUCT lpCreateStruct)579 int CUnmasswDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
580 {
581 	if (CDialog::OnCreate(lpCreateStruct) == -1)
582 		return -1;
583 
584 //	WndDataInitialized = 0;
585 
586 	return 0;
587 }
588 
OnDblclkLISTfiles(NMHDR * pNMHDR,LRESULT * pResult)589 void CUnmasswDlg::OnDblclkLISTfiles(NMHDR* pNMHDR, LRESULT* pResult)
590 {
591 	POSITION		pos = m_list.GetFirstSelectedItemPosition();
592 	int				nItem, res;
593 	unsigned long	count = 0;//, files;
594 //	char			str[ 512 ];
595 
596 	if ( pos != NULL ) {
597 
598 		m_info = "Extracting file into temp directory";
599 		UpdateData( false );
600 
601 		//create temp directory
602 		mkdir( TempDir );
603 
604 		nItem = InListPos[ m_list.GetNextSelectedItem( pos ) ];
605 
606 		memcpy( &mass.FileRec, &FileInfo[nItem].FileRec, sizeof( CMassArchive::s_FileRec ) );
607 		sprintf( mass.FileRec.name, "%s\\%s",
608 			TempDir, FileInfo[nItem].FileRec.name );
609 
610 		if ( mass.Extract() == 0 )
611 			MessageBox( mass.GetErrorStr() );
612 		else {
613 			//file is extracted. now run command
614 
615 			m_info = "Running command...";
616 			UpdateData( false );
617 
618 			res = (int) ShellExecute( NULL, "open", mass.FileRec.name, NULL, NULL, SW_SHOW );
619 
620 			if ( res > 32 )
621 				m_info = "previewing returned succes";
622 			else
623 				m_info = "previewing returned error, probably no program is assigned to filetype";
624 			UpdateData( false );
625 		}
626 	}
627 
628 	*pResult = 0;
629 }
630 
OnBUTTONselAdd()631 void CUnmasswDlg::OnBUTTONselAdd()
632 {
633 	DoSelect( 1 );
634 }
635 
OnBUTTONselRem()636 void CUnmasswDlg::OnBUTTONselRem()
637 {
638 	DoSelect( 0 );
639 }
640 
DoSelect(int select)641 void CUnmasswDlg::DoSelect( int select )
642 {
643 	int				len, i, item;
644 	unsigned long	lu, state, count;
645 
646 	CString			cstr;
647 
648 	UpdateData();
649 
650 	if ( select )
651 		state = LVIS_SELECTED;
652 	else
653 		state = 0;
654 
655 	i = m_SelTypes.GetCurSel();
656 	if ( i == CB_ERR )
657 		return;
658 
659 	item = m_SelTypes.GetItemData( i );
660 	if ( item != - 1 )
661 		len = strlen( FileInfo[ item ].FileRec.type );
662 
663 	count = 0;
664 
665 	for( lu=0; lu<mass.MassfInfo.files_count; lu++ )
666 		if (( item == -1 ) ||
667 			(( strlen( FileInfo[ InListPos[ lu ] ].FileRec.type ) == len ) &&
668 			 ( memcmp( FileInfo[ InListPos[ lu ] ].FileRec.type,
669 				FileInfo[ item ].FileRec.type, len ) == 0 )
670 			)
671 			) {
672 //			m_list.SetItemState( InListPos[ lu ], state, LVIS_SELECTED );
673 			m_list.SetItemState( lu, state, LVIS_SELECTED );
674 			count++;
675 		}
676 
677 	m_info.Format( "%sselected %lu files", select ? "" : "un", count );
678 	UpdateData( false );
679 }
680 
NewFileIntoList(unsigned long listpos)681 void CUnmasswDlg::NewFileIntoList( unsigned long listpos )
682 {
683 	int		i, j, res;
684 
685 	memcpy( &FileInfo[ listpos ].FileRec, &mass.FileRec,
686 		sizeof( CMassArchive::s_FileRec ) );
687 
688 	//ak modul sam nevyplna type, tak tam dam extension
689 	if (( mass.MassfInfo.flags & CMassArchive::ma_flag_fills_type ) == 0 ) {
690 		i = strlen( FileInfo[ listpos ].FileRec.name );
691 		while (( i > 0 ) && ( FileInfo[ listpos ].FileRec.name[ i-1 ] != '.' ))
692 			i--;
693 
694 		if ( i == 0 )
695 			FileInfo[ listpos ].FileRec.type[0] = 0;
696 		else {
697 			j = strlen( FileInfo[ listpos ].FileRec.name ) - i;
698 			if ( j > CMassArchive::TypeMaxLen )
699 				j = CMassArchive::TypeMaxLen-1;
700 			memcpy( FileInfo[ listpos ].FileRec.type, &FileInfo[ listpos ].FileRec.name[ i ], j );
701 			FileInfo[ listpos ].FileRec.type[ j ] = 0;
702 		}
703 	}
704 
705 	//pridam si typ do select comba
706 	res = m_SelTypes.FindStringExact( 0, FileInfo[ listpos ].FileRec.type );
707 	if (( res == CB_ERR ) && ( FileInfo[ listpos ].FileRec.type[0] == 0 ) &&
708 		( NoExtInCombo == 1 ))
709 		res = 0;
710 
711 	if ( res == CB_ERR ) {
712 		m_SelTypes.SetItemData(
713 			m_SelTypes.AddString( FileInfo[ listpos ].FileRec.type ), listpos );
714 
715 		if ( FileInfo[ listpos ].FileRec.type[ 0 ] == 0 )
716 			NoExtInCombo = 1;
717 	}
718 
719 }
720 
ReopenFileForWriting(void)721 int CUnmasswDlg::ReopenFileForWriting( void )
722 {
723 	long	attr, i;
724 
725 	if ( mass.ReopenForWriting() == 0 ) {
726 
727 		attr = GetFileAttributes( mass.MassfInfo.filenm );
728 		if ( attr == -1 ) {
729 			m_info = "Could not get file attributes";
730 			MessageBox( "Could not get file attributes" );
731 			return 0;
732 		}
733 
734 		if ( attr & FILE_ATTRIBUTE_READONLY ) {
735 
736 			i = MessageBox( "File is read only, I have to remove read-only attribute",
737 				NULL, MB_OKCANCEL | MB_ICONWARNING );
738 
739 			if ( i == IDCANCEL ) {
740 				MessageBox( "Can't modify file with read-only attribute" );
741 				return 0;
742 			}
743 
744 			attr = attr ^ FILE_ATTRIBUTE_READONLY;
745 			if ( SetFileAttributes( mass.MassfInfo.filenm, attr ) == 0 ) {
746 				MessageBox( "Could not set file attribute !!" );
747 				return 0;
748 			}
749 
750 		}
751 		else {
752 			MessageBox( "File error, cannot open for writing", NULL, MB_ICONERROR );
753 			return 0;
754 		}
755 
756 	}
757 
758 	return 1;
759 }
760 
OnBUTTONaddFile()761 void CUnmasswDlg::OnBUTTONaddFile()
762 {
763 
764 #define FNAME_BUF_SIZE 20000
765 
766 	CFileDialog		dlg( true, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_ENABLESIZING |
767 				OFN_FILEMUSTEXIST | OFN_HIDEREADONLY , "*.*|*.*||", this );
768 	POSITION		pos;
769 	CString			cstr;
770 	int				i, index, files, fi;
771 	s_FileInfo		*pFileInfo;
772 	unsigned long	*pul, files_before;
773 	int				res;
774 	char			fnamebuf[ FNAME_BUF_SIZE ];
775 
776 	if ( ReopenFileForWriting() == 0 )
777 		return;
778 
779 //	fnamebuf = ( char* ) malloc( FNAME_BUF_SIZE );
780 //	if ( fnamebuf == NULL ) {
781 //		MessageBox( "Not enough mem for allocating buffer" );
782 //		return;
783 //	}
784 
785 //	dlg.m_ofn.Flags = | OFN_ENABLEHOOK;
786 	dlg.m_ofn.lpstrFile = fnamebuf;
787 	dlg.m_ofn.nMaxFile	= FNAME_BUF_SIZE;
788 	memset( fnamebuf, ' ', FNAME_BUF_SIZE );
789 	fnamebuf[ FNAME_BUF_SIZE-1 ] = 0;
790 
791 	i = dlg.DoModal();
792 	fi = CommDlgExtendedError();
793 
794 	if (( i == 2 ) && ( fi == 0x3003 ))
795 		MessageBox( "You have selected too many files ... try again" );
796 
797 	if ( i == IDOK ) {
798 
799 		pos = dlg.GetStartPosition();
800 		files = 0;
801 		while( pos ) {
802 			dlg.GetNextPathName( pos );
803 			files++;
804 		}
805 
806 
807 		cstr.Format( "Are you sure to add %i file(s) ?", files );
808 		res = MessageBox( cstr, NAME_VER, MB_YESNO | MB_ICONQUESTION );
809 		if ( res == IDNO ) {
810 //			free( fnamebuf );
811 			return;
812 		}
813 
814 
815 		pos = dlg.GetStartPosition();
816 		index = -1;
817 
818 		files_before = mass.MassfInfo.files_count;
819 
820 
821 		GetDlgItem( IDC_STATICinfo )->ShowWindow( false );
822 		m_progress.ShowWindow( true );
823 		m_progress.SetPos( 0 );
824 		UpdateData( false );
825 
826 		fi = 0;
827 
828 		while ( pos != NULL ) {
829 
830 			m_progress.SetPos( fi * 100 / files );
831 			UpdateData( false );
832 
833 			fi++;
834 
835 			//filename
836 			cstr = dlg.GetNextPathName( pos );
837 			//get filename without path
838 			i = cstr.ReverseFind( '\\' );
839 
840 			index = mass.AddFile( cstr.GetBuffer(0),
841 				cstr.Right( cstr.GetLength() - i - 1 ).GetBuffer(0) );
842 
843 			if ( index == -1 ) {
844 				cstr.Format( "Error adding file #%i", fi );
845 				MessageBox( cstr, "Error", MB_OK | MB_ICONEXCLAMATION );
846 				break;
847 			}
848 
849 		}
850 
851 		// ak sa pridali nejake subory, tak ich pridam do listu a presortujem
852 		//while je to preto aby som to mohol break-nut
853 		while ( index != -2 ) {
854 			//add into list
855 			pFileInfo = ( s_FileInfo* )
856 				realloc( FileInfo,
857 						sizeof( s_FileInfo ) * mass.MassfInfo.files_count );
858 			if ( pFileInfo == NULL ) {
859 				MessageBox( "Out of memory, cannot display new file" );
860 				break;
861 			}
862 			FileInfo = pFileInfo;
863 
864 			pul = (unsigned long*)
865 				realloc( InListPos,
866 						sizeof( unsigned long ) * mass.MassfInfo.files_count );
867 			if ( pul == NULL ) {
868 				MessageBox( "Out of memory, cannot display new file" );
869 				break;
870 			}
871 			InListPos = pul;
872 
873 			for( i=files_before; i<mass.MassfInfo.files_count; i++ ) {
874 				mass.ReadRecords();
875 			}
876 			for( i=files_before; i<mass.MassfInfo.files_count; i++ ) {
877 				NewFileIntoList( i );
878 			}
879 
880 			//aby to presortovalo
881 			sort = sort_displayed;
882 			sort_displayed = sort_undefined;
883 			FillListSorted( sort );
884 
885 			index = -2;
886 		}
887 
888 		m_progress.ShowWindow( false );
889 		GetDlgItem( IDC_STATICinfo )->ShowWindow( true );
890 
891 	}
892 
893 //	free( fnamebuf );
894 }
895 
OnBUTTONaddDir()896 void CUnmasswDlg::OnBUTTONaddDir()
897 {
898 
899 	CFileDialog		dlg( true, NULL, "this one", OFN_NOVALIDATE, "Choose directory|mirex rules!||", this );
900 //	char			path[ 4096 ];
901 	int				pos, oripathlen;
902 
903 	CStringArray	dirs;
904 	CString			dir, cstr, cstr2, path;
905 	long			res, findh;
906 	_finddata_t		find;
907 	int				files_before, files, index, fi, i;
908 	s_FileInfo		*pFileInfo;
909 	unsigned long	*pul;
910 
911 
912 	chdir( OutputDir );
913 
914 	if ( dlg.DoModal() == IDOK ) {
915 
916 		if ( ReopenFileForWriting() == 0 )
917 			return;
918 
919 		cstr = dlg.GetPathName();
920 
921 		pos = cstr.ReverseFind( '\\' );
922 		if ( pos == -1 )
923 			return;
924 
925 		cstr.Delete( pos, cstr.GetLength() - pos );
926 
927 		path = cstr;
928 		oripathlen = path.GetLength();
929 
930 /*
931 	CString		cstr;
932 	int			res;
933 	BROWSEINFO	bi;
934 	ITEMIDLIST	srcdir, *idl;
935 	char		pth[ MAX_PATH ];
936 
937 
938 
939 	memset( &bi, 0, sizeof( bi ) );
940 
941 	srcdir.
942 	bi.hwndOwner	= this->GetSafeHwnd();
943 	bi.pidlRoot		= &srcdir;
944 	bi.pszDisplayName	= pth;
945 	bi.lpszTitle	= NULL;
946 	bi.ulFlags		= BIF_BROWSEINCLUDEFILES | BIF_EDITBOX;
947 	bi.lpfn			= NULL;
948 
949 
950 	idl = SHBrowseForFolder( &bi );
951 
952 	free( bi.pszDisplayName );
953 
954 	if ( idl == NULL )
955 		return;
956 */
957 
958 
959 		files = 0;
960 
961 		dirs.Add( cstr );
962 
963 		while ( dirs.GetSize() > 0 ) {
964 
965 			dir = dirs.GetAt( 0 );
966 			dirs.RemoveAt( 0 );
967 
968 			cstr = dir + "\\*.*";
969 
970 			res = findh = _findfirst( cstr, &find );
971 
972 			while ( res != -1 ) {
973 
974 				if ( find.attrib & _A_SUBDIR ) {
975 
976 					if (( strcmp( find.name, "." ) != 0 ) &&
977 						( strcmp( find.name, ".." ) != 0 ))
978 
979 						dirs.Add( dir + "\\" + find.name );
980 
981 				}
982 				else
983 					files++;
984 
985 				res = _findnext( findh, &find );
986 			} ;
987 
988 		} ;
989 
990 		_findclose( findh );
991 
992 		cstr.Format( "Are you sure to add this directory (containing %i files) ?", files );
993 		res = MessageBox( cstr, NAME_VER, MB_YESNO | MB_ICONQUESTION );
994 		if ( res == IDNO )
995 			return;
996 
997 		files_before = mass.MassfInfo.files_count;
998 
999 		// now go add `em
1000 
1001 		GetDlgItem( IDC_STATICinfo )->ShowWindow( false );
1002 		m_progress.ShowWindow( true );
1003 		m_progress.SetPos( 0 );
1004 		UpdateData( false );
1005 
1006 		fi = 0;
1007 
1008 		dirs.Add( path );
1009 
1010 		while ( dirs.GetSize() > 0 ) {
1011 
1012 			dir = dirs.GetAt( 0 );
1013 			dirs.RemoveAt( 0 );
1014 
1015 			cstr = dir + "\\*.*";
1016 
1017 			res = findh = _findfirst( cstr, &find );
1018 
1019 			while ( res != -1 ) {
1020 
1021 				if ( find.attrib & _A_SUBDIR ) {
1022 
1023 					if (( strcmp( find.name, "." ) != 0 ) &&
1024 						( strcmp( find.name, ".." ) != 0 ))
1025 
1026 						dirs.Add( dir + "\\" + find.name );
1027 
1028 				}
1029 				else {
1030 					m_progress.SetPos( fi * 100 / files );
1031 					UpdateData( false );
1032 
1033 					fi++;
1034 					if ( fi >= files )
1035 						fi = 0;
1036 
1037 					cstr = dir + "\\" + find.name;
1038 					cstr2 = cstr;
1039 					cstr2.Delete( 0, oripathlen+1 );
1040 
1041 					index = mass.AddFile( cstr.GetBuffer(0), cstr2.GetBuffer(0) );
1042 
1043 					if ( index == -1 ) {
1044 						cstr2.Format( "Error adding file #%i\n(%s)\n%s",
1045 							fi, cstr, mass.GetErrorStr() );
1046 						MessageBox( cstr2.GetBuffer(0), "Error", MB_OK | MB_ICONEXCLAMATION );
1047 						dirs.RemoveAll();
1048 						break;
1049 					}
1050 
1051 				}
1052 
1053 				res = _findnext( findh, &find );
1054 			} ;
1055 
1056 			_findclose( findh );
1057 
1058 		} ;
1059 
1060 
1061 		// ak sa pridali nejake subory, tak ich pridam do listu a presortujem
1062 		//while je to preto aby som to mohol break-nut
1063 		while ( index != -2 ) {
1064 			//add into list
1065 			pFileInfo = ( s_FileInfo* )
1066 				realloc( FileInfo,
1067 						sizeof( s_FileInfo ) * mass.MassfInfo.files_count );
1068 			if ( pFileInfo == NULL ) {
1069 				MessageBox( "Out of memory, cannot display new file" );
1070 				break;
1071 			}
1072 			FileInfo = pFileInfo;
1073 
1074 			pul = (unsigned long*)
1075 				realloc( InListPos,
1076 						sizeof( unsigned long ) * mass.MassfInfo.files_count );
1077 			if ( pul == NULL ) {
1078 				MessageBox( "Out of memory, cannot display new file" );
1079 				break;
1080 			}
1081 			InListPos = pul;
1082 
1083 			for( i=files_before; i<mass.MassfInfo.files_count; i++ ) {
1084 				mass.ReadRecords();
1085 			}
1086 			for( i=files_before; i<mass.MassfInfo.files_count; i++ ) {
1087 				NewFileIntoList( i );
1088 			}
1089 
1090 			//aby to presortovalo
1091 			sort = sort_displayed;
1092 			sort_displayed = sort_undefined;
1093 			FillListSorted( sort );
1094 
1095 			index = -2;
1096 		}
1097 
1098 		m_progress.ShowWindow( false );
1099 		GetDlgItem( IDC_STATICinfo )->ShowWindow( true );
1100 
1101 
1102 	}
1103 }
1104 
OnBUTTONunlinkFile()1105 void CUnmasswDlg::OnBUTTONunlinkFile()
1106 {
1107 	CString			cstr;
1108 	int				res;
1109 	POSITION		pos;
1110 	int				nItem;
1111 	unsigned long	fi, fc, i;
1112 
1113 	if ( ReopenFileForWriting() == 0 )
1114 		return;
1115 
1116 	fc = m_list.GetSelectedCount();
1117 	if ( fc == 0 ) {
1118 		m_info = "No files selected";
1119 		UpdateData( false );
1120 		return;
1121 	}
1122 
1123 	cstr.Format( "Are you sure to unlink %i files ?", fc );
1124 	res = MessageBox( cstr, NAME_VER, MB_YESNO | MB_ICONQUESTION );
1125 	if ( res == IDNO )
1126 		return;
1127 
1128 
1129 	GetDlgItem( IDC_STATICinfo )->ShowWindow( false );
1130 	m_progress.ShowWindow( true );
1131 	m_progress.SetPos( 0 );
1132 	UpdateData( false );
1133 
1134 	pos = m_list.GetFirstSelectedItemPosition();
1135 	fi = 0;
1136 
1137 	cstr = "Success.";
1138 
1139 	while ( pos != NULL ) {
1140 
1141 		m_progress.SetPos( fi * 100 / fc );
1142 		UpdateData( false );
1143 
1144 		nItem = InListPos[ m_list.GetNextSelectedItem( pos ) ];
1145 
1146 		if ( mass.UnlinkFile( nItem ) == 0 ) {
1147 			cstr.Format( "Error unlinking file #%i. (%s)", nItem, mass.GetErrorStr() );
1148 			MessageBox( cstr, NULL, MB_ICONWARNING | MB_OK );
1149 			break;
1150 		}
1151 
1152 		//odstranim subor z listu
1153 		for( i=nItem; i<mass.MassfInfo.files_count; i++ )
1154 			memcpy( &FileInfo[ i ], &FileInfo[ i+1 ], sizeof( s_FileInfo ) );
1155 
1156 		//musim odstranit aj zo select listu, lebo inak by som dostaval zle indexy
1157 		m_list.DeleteItem( nItem );
1158 		pos = m_list.GetFirstSelectedItemPosition();
1159 
1160 	} ;
1161 
1162 	UpdateData( false );
1163 
1164 	// resort
1165 	sort = sort_displayed;
1166 	sort_displayed = sort_undefined;
1167 	FillListSorted( sort );
1168 
1169 	m_info = cstr;
1170 
1171 	GetDlgItem( IDC_STATICinfo )->ShowWindow( true );
1172 	m_progress.ShowWindow( false );
1173 }
1174 
OnBUTTONdelFile()1175 void CUnmasswDlg::OnBUTTONdelFile()
1176 {
1177 
1178 	if ( ReopenFileForWriting() == 0 )
1179 		return;
1180 
1181 	MessageBox( "Unsupported yet" );
1182 /*
1183 delete
1184 */
1185 
1186 
1187 }
1188 
OnBUTTONcreateArchive()1189 void CUnmasswDlg::OnBUTTONcreateArchive()
1190 {
1191 	CString			filter, cstr, ext, cstr2;
1192 	int				i, j, l, type;
1193 	FILE			*f;
1194 	CChArchType		ChooseArchType;
1195 
1196 	CloseArchive();
1197 
1198 	filter = "";
1199 	for( i=0; i<mass.massftypes_count; i++ ) {
1200 
1201 		if (( mass.Archive[ i ]->GetFlags() & CMassArchive::ma_flag_create_archive ) == 0 )
1202 			continue;
1203 
1204 		cstr.Format( "%s",
1205 			mass.Archive[ i ]->GetIdent() );
1206 
1207 		ChooseArchType.data.Add( i );
1208 		ChooseArchType.strings.Add( cstr );
1209 
1210 	}
1211 
1212 	if ( ChooseArchType.DoModal() == IDCANCEL )
1213 		return;
1214 
1215 	type = ChooseArchType.choice;
1216 	if ( type == CB_ERR ) {
1217 		MessageBox( "No type chosen" );
1218 		return;
1219 	}
1220 
1221 	filter.Format( "%s|%s||", mass.Archive[ type ]->GetIdent(),
1222 		mass.TypeExtToWinDlgExt( type ) );
1223 
1224 
1225 	CFileDialog		fd( true, mass.GetTypeFirstExt( type ), "file name",
1226 						OFN_OVERWRITEPROMPT, filter, this );
1227 
1228 	i = fd.DoModal();
1229 	if ( i == IDOK ) {
1230 
1231 		f = fopen( fd.GetPathName().GetBuffer(0), "rb" );
1232 		if ( f != NULL ) {
1233 			fclose( f );
1234 
1235 			l = MessageBox( "File already exists, overwrite ?", NULL, MB_YESNO );
1236 
1237 			if ( l == IDNO )
1238 				return;
1239 		}
1240 
1241 		i = mass.CreateNewArchive( fd.GetPathName().GetBuffer(0), type );
1242 
1243 		if ( i == 0 ) {
1244 			m_info = mass.GetErrorStr();
1245 			UpdateData( false );
1246 			MessageBox( mass.GetErrorStr(), "Error creating archive", MB_ICONEXCLAMATION );
1247 			return;
1248 		}
1249 
1250 //		MessageBox( "Archive created." );
1251 
1252 		OpenArchive( fd.GetPathName().GetBuffer(0) );
1253 
1254 	}
1255 }
1256 
CloseArchive()1257 void CUnmasswDlg::CloseArchive()
1258 {
1259 
1260 	mass.Close();
1261 
1262 	GetDlgItem( IDC_BUTTONaddFile	)->EnableWindow( false );
1263 	GetDlgItem( IDC_BUTTONaddDir	)->EnableWindow( false );
1264 	GetDlgItem( IDC_BUTTONunlinkFile)->EnableWindow( false );
1265 	GetDlgItem( IDC_BUTTONdelFile	)->EnableWindow( false );
1266 
1267 //	GetDlgItem( IDC_BUTTONcreateArchive	)->EnableWindow( true );
1268 
1269 	GetDlgItem( IDC_BUTTONopen )->SetWindowText( BUTTON_OPEN_STRING );
1270 
1271 	UpdateData( false );
1272 
1273 	getcwd( OpenDir, MaxPathLength );
1274 
1275 	m_info = "Purging list";
1276 	UpdateData( false );
1277 
1278 	m_list.DeleteAllItems();
1279 
1280 	m_info = "Purging file info";
1281 	UpdateData( false );
1282 
1283 	if ( FileInfo != NULL ) {
1284 		free( FileInfo );
1285 		FileInfo = NULL;
1286 	}
1287 //	FileInfo.RemoveAll();
1288 
1289 	if ( InListPos != NULL ) {
1290 		free( InListPos );
1291 		InListPos = NULL;
1292 	}
1293 
1294 	ArchiveOpened = 0;
1295 
1296 	m_info = "";
1297 	UpdateData( false );
1298 }
1299 
OpenArchive(char * filename)1300 int CUnmasswDlg::OpenArchive( char* filename )
1301 {
1302 	int		i, l;
1303 
1304 	m_info = "Opening file";
1305 	UpdateData( false );
1306 
1307 	if ( ! mass.Open( filename ) ) {
1308 		MessageBox( "Unknown file format...", "oops" );
1309 		m_info2 = "Unsupported format...";
1310 		return 0;
1311 	}
1312 
1313 	FileInfo = ( s_FileInfo* )
1314 		malloc( sizeof( s_FileInfo ) * mass.MassfInfo.files_count );
1315 
1316 	InListPos = (unsigned long*)
1317 		malloc( sizeof( unsigned long ) * mass.MassfInfo.files_count );
1318 
1319 	if (( FileInfo == NULL ) || ( InListPos == NULL )) {
1320 //		if ( InListPos == NULL ) {
1321 		MessageBox( "Out of memory" );
1322 		EndDialog( -1 );
1323 		return 0;
1324 	}
1325 
1326 	m_info2.Format( "type: %s, files: %lu",
1327 		mass.GetTypeIdentString( mass.MassfInfo.type ),
1328 		mass.MassfInfo.files_count );
1329 
1330 	OutputPath.Format( "%s%s", mass.MassfInfo.filedir,
1331 		mass.MassfInfo.filename );
1332 
1333 	m_DirButton.SetWindowText( OutputPath.GetBuffer(0) );
1334 
1335 	m_SelTypes.ResetContent();					// selection types
1336 	m_SelTypes.SetItemData( m_SelTypes.AddString( "*" ), -1 );
1337 	// data budu ukazovat do listu na subor toho isteho typu
1338 
1339 //		GetDlgItem( IDC_STATICinfo )->ShowWindow( false );
1340 	m_progress.ShowWindow( true );
1341 
1342 	m_info = "Loading file list";
1343 	UpdateData( false );
1344 
1345 	NoExtInCombo = 0;
1346 
1347 	//prednahratie vsetkych zaznamov
1348 
1349 	for( l=0; l<mass.MassfInfo.files_count; l++ ) {
1350 
1351 		mass.ReadRecords();
1352 
1353 		if ( (l+1) % 500 == 0 ) {
1354 			m_progress.SetPos( l * 100 / mass.MassfInfo.files_count );
1355 			UpdateData( false );
1356 		}
1357 
1358 	}
1359 
1360 	for( l=0; l<mass.MassfInfo.files_count; l++ ) {
1361 
1362 //			if ( l == 0 )
1363 //				mass.ReadRec( 0 );
1364 //			else
1365 //				mass.ReadRec( -1 );
1366 		mass.GetRec( l );
1367 /*
1368 		memcpy( FileInfo[l].FileRec.name, mass.FileRec.name,
1369 					FileNameWithPathMaxLen );
1370 		FileInfo[l].FileRec.name[ FileNameWithPathMaxLen-1 ] = 0;
1371 		FileInfo[l].FileRec.offset = mass.FileRec.offset;
1372 		FileInfo[l].FileRec.size   = mass.FileRec.size;
1373 		FileInfo[l].FileRec.flag   = mass.FileRec.flag;
1374 		mass.FileRec.type[ TypeMaxLen-1 ] = 0;
1375 		memcpy( FileInfo[l].FileRec.type, mass.FileRec.type, TypeMaxLen );
1376 */
1377 //			FileInfo.Add( &mass.FileRec );
1378 
1379 		NewFileIntoList( l );
1380 
1381 		//put info about where am i in progress, often
1382 		if ( (l+1) % 500 == 0 ) {
1383 			m_progress.SetPos( l * 100 / mass.MassfInfo.files_count );
1384 			UpdateData( false );
1385 		}
1386 
1387 	}
1388 
1389 	m_progress.ShowWindow( false );
1390 
1391 	m_info = "Displaying list";
1392 	UpdateData( false );
1393 
1394 	sort = sort_unsorted;
1395 	sort_displayed = sort_undefined;
1396 	FillListSorted( sort );
1397 
1398 	m_info.Format( "name: [%s]", mass.MassfInfo.filenm );
1399 
1400 //		GetDlgItem( IDC_STATICinfo )->ShowWindow( true );
1401 
1402 	//vyberiem z ext listu '*'
1403 	for( i=0; i<m_SelTypes.GetCount(); i++ )
1404 		if ( m_SelTypes.GetItemData( i ) == -1 ) {
1405 			m_SelTypes.SetCurSel( i );
1406 			break;
1407 		}
1408 
1409 	if ( mass.MassfInfo.flags & CMassArchive::ma_flag_add_file )
1410 		GetDlgItem( IDC_BUTTONaddFile )->EnableWindow( true );
1411 	if ( mass.MassfInfo.flags & CMassArchive::ma_flag_add_file )
1412 		GetDlgItem( IDC_BUTTONaddDir	)->EnableWindow( true );
1413 	if ( mass.MassfInfo.flags & CMassArchive::ma_flag_unlink_file )
1414 		GetDlgItem( IDC_BUTTONunlinkFile)->EnableWindow( true );
1415 	if ( mass.MassfInfo.flags & CMassArchive::ma_flag_delete_file )
1416 		GetDlgItem( IDC_BUTTONdelFile	)->EnableWindow( true );
1417 	if ( mass.MassfInfo.flags & CMassArchive::ma_flag_create_archive )
1418 		GetDlgItem( IDC_BUTTONcreateArchive	)->EnableWindow( true );
1419 
1420 	ArchiveOpened = 1;
1421 	GetDlgItem( IDC_BUTTONopen )->SetWindowText( BUTTON_CLOSE_STRING );
1422 
1423 	UpdateData( false );
1424 
1425 	if ( mass.MassfInfo.flags &
1426 		( CMassArchive::ma_flag_add_file |
1427 		CMassArchive::ma_flag_unlink_file |
1428 		CMassArchive::ma_flag_delete_file )) {
1429 
1430 		MessageBox(
1431 "Watch out !\n\
1432 All changes are done real-time, so back-up your original files before changes !\n\
1433 Although it should work, mistakes may happen and files might get damaged by accident.\n\
1434 You have been warned !\n",
1435 			"Be careful", MB_OK | MB_ICONEXCLAMATION );
1436 	}
1437 
1438 	return 1;
1439 }
1440 
OnCancel()1441 void CUnmasswDlg::OnCancel()
1442 {
1443 	// Escape key does nothing
1444 //	CDialog::OnCancel();
1445 }
1446 
OnClose()1447 void CUnmasswDlg::OnClose()
1448 {
1449 	// Closing program does OnCancel
1450 	CDialog::OnClose();
1451 	CDialog::OnCancel();
1452 }
1453