DAS  3.1.6 - 18/09/2017
DFileMan.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <conio.h>
3 #include <direct.h>
4 #include <ctype.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <math.h>
9 #include <fcntl.h>
10 #include <string.h>
11 #include <io.h>
12 #include <sys/stat.h>
13 #include "mgui.h"
14 #include <direct.h>
15 #include "bil.h"
16 #include "dcldef.h"
17 //#include "dtadef.h"
18 #include "DAS_Spatram.h"
19 
20 
28 
29 char *DDRIVE;
30 char DFMT[8];
31 char *OLDPATH;
32 char *DFNAME;
33 int SELDRV;
34 int FMINIT;
35 int FMDONE;
36 
45 
47 
49 
50 /*
51  * Shell creation prototypes
52  */
53 
54 /*
55  * Project Defined Callbacks
56  */
57 
58 /*
59  * Shell creation functions
60  */
61 
62 void ShowFileDrive(char *idir, char *ext)
63 {
64 
65  struct _finddata_t ffblk;
66  char str[_MAX_PATH];
67  int i, done, handle;
68 
70  //sprintf(str, "%s\\*.*", idir);
71  //sprintf(str, "%s\*.*", idir);
72  sprintf(str, "%s\\%s", idir, "*.*");
74 
75  handle = _findfirst(str, &ffblk);
76  i = 0;
77  // All
78  done = 0;
79  do
80  {
81 
82  done = _findnext(handle, &ffblk);
83  if(done == 0 && (ffblk.attrib & _A_SUBDIR) == _A_SUBDIR)
84  {
85  sprintf(str, "[%s]", ffblk.name);
86 
87  MSListAddItem(FList, str, (void *) i);
88  }
89  i++;
90  }while(done == 0);
91 
92 // sprintf(str, "%s\\*%s", idir, ext);
93 sprintf(str, "%s\\%s", idir, ext);
94  handle = _findfirst(str, &ffblk);
95  // Ext
96  done = 0;
97  if(strcmp(ext,"*.*") == 0)
98  {
99  do
100  {
101  done = _findnext(handle, &ffblk);
102  strcpy(str, _strupr(ffblk.name));
103 // if(strncmp(&str[strlen(str) - 4], ext, 4) == 0)
104  MSListAddItem(FList, str, (void *) i);
105  ffblk.name[0] = 0;
106  i++;
107  }while(done == 0);
108 
109  }
110  else
111  {
112  do
113  {
114  done = _findnext(handle, &ffblk);
115  strcpy(str, _strupr(ffblk.name));
116  if(strncmp(&str[strlen(str) - 4], &ext[strlen(ext) - 4], 4) == 0)
117  MSListAddItem(FList, str, (void *) i);
118  ffblk.name[0] = 0;
119  i++;
120  }while(done == 0);
121  }
122 
123 }
124 
125 
126 void ChDriveCB(MOBJECT rb, MVALUE s, void *ad)
127 {
128  int w = (int) ad;
129  char buf[64];
130 
131  if(s)
132  {
133  SELDRV = w;
134  _chdrive(w);
135  MObjectGetText(rb, buf);
136 
137  DDRIVE = buf; // = C:
138 
140 
141  sprintf(buf, "%s\\", buf); // = C:\
142  MObjectSetText(txtpath, buf);
143 
144  sprintf(buf, "%s", DFMT);
145  MObjectSetText(txtfile, buf);
146 
147 
148  }
149 
150 }
151 
152 void DFileType(int i)
153 {
154 
155 
156  switch((int) i)
157  {
158  case FDAT: strcpy(DFMT,"*.DAT"); break;
159  case FMAP: strcpy(DFMT,"*.MAP"); break;
160  case FELE: strcpy(DFMT,"*.ELE"); break;
161  case FALL: strcpy(DFMT,"*.*"); break;
162  case FRIS: strcpy(DFMT,"*.RIS"); break;
163  case FFID: strcpy(DFMT,"*.FIN"); break;
164  case FCOL: strcpy(DFMT,"*.COL"); break;
165  case FMOD: strcpy(DFMT,"*.MOD"); break;
166  case FBIF: strcpy(DFMT,"*.BIF"); break;
167 
168  }
169 
170 
171 
172 
173 }
174 
175 void DFMSelListCB(MOBJECT p, LIST_ACT *la, void *v)
176 {
177  char str[256];
178  char buf[256],buf1[256];
179  int flgbs = 0, i,STRLEN;
180 // char *path;
181  static int reent;
182  if(reent != 0 && reent != 1) reent = 0;
183  if(reent == 1) return;
184  reent = 1;
185  strcpy(str, la->item);
186 
187  if(str[0] == '[')
188  {
189  if(str[1] != '.')
190  {
191 
192  la->item[strlen(la->item) - 1] = 0;
193 
194 // MObjectGetText(DRV[SELDRV], buf);
195 
196  MObjectGetText(txtpath, buf);
197 
198  DDRIVE = buf;
199  strcpy(buf, DDRIVE);
200 
201  strcat(buf, &la->item[1]);
202  _chdir(buf);
203  strcpy(buf1,buf);
204  strcat(buf1,"\\");
205  }
206  if(str[1] == '.')
207  {
208  i=2;
209  flgbs = 0;
210  MObjectGetText(txtpath, buf);
211  STRLEN = strlen(buf);
212  do {
213  if(buf[STRLEN - i] != 0x5C)
214  {
215  buf[STRLEN - i] = 0;
216  i++;
217  }
218  else
219  {
220  flgbs = 1;
221  buf[STRLEN - i] = 0;
222 
223  }
224  }while (flgbs == 0);
225 
226 
227  _chdir(buf);
228  strcpy(buf1,buf);
229  strcat(buf1,"\\");
230 
231  }
232 // MObjectGetText(txtfile, DFMT);
233 
234  ShowFileDrive(buf, DFMT);
235 
236 
237 // if(buf[strlen(buf) - 1] != 0x5C)
238 // strcat(buf, "\\");
239 
240 
241 // MObjectSetText(txtpath, "");
242 // ShowFileDrive(buf, DFMT);
243 // MObjectSetText(txtpath, buf);
244 
245 /*
246 #ifdef _WIN32
247  if(buf[strlen(buf) - 1] != 0x5C)
248  strcat(buf, "\\");
249 #else
250  if(buf[strlen(buf) - 1] != 0x2F)
251  strcat(buf, "/");
252 #endif
253 */
254  MObjectSetText(txtpath, buf1);
255 
256 
257  }
258  else
259  {
260  strcpy(DFNAME, la->item);
262  }
263  reent = 0;
264 
265 }
266 
267 void DFMCloseCB(void)
268 {
269 
270  FMDONE = 1;
271  FMINIT = 1;
272 }
273 
274 void D_FMDoneCB(MOBJECT shell, void *od, void *ad)
275 {
276  int w = (int) ad;
277  char buff[256];
278  char str[256];
279  switch(w)
280  {
281  case 0:
282  MObjectGetText(txtpath, buff);
283  sprintf(BIL.DFILEM.WORKDIRECTORY, "%s",buff);
284  MObjectGetText(txtfile, str);
285  strcat(buff, str);
286  sprintf(BIL.DFILEM.DBFILENAME, "%s", buff);
287 
288  DFMCloseCB();
289  break;
290  case 1:
291  BIL.DFILEM.DBFILENAME[0] = 0;
292  DFMCloseCB();
293  break;
294  case 2:
295  MObjectGetText(txtpath, buff);
296  MObjectGetText(txtfile, str);
297  strcat(buff, str);
298  sprintf(BIL.DFILEM.DBFILENAME, "%s", buff);
299  DFMCloseCB();
300  break;
301 
302  }
303 }
304 
305 
306 int WhoSys(void)
307 {
308 #ifdef _WIN32
309  int so;
310  OSVERSIONINFOEX osvi;
311  BOOL bOsVersionInfoEx;
312 
313  ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
314  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
315 
316  if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
317  {
318  // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
319  osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
320  if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
321  return 0;
322  }
323 
324  switch (osvi.dwPlatformId)
325  {
326  // NT, 2000
327  case VER_PLATFORM_WIN32_NT:
328  so = WIN_NT;
329  break;
330  // 95, 98, Me
331  case VER_PLATFORM_WIN32_WINDOWS:
332  so = 0;
333  break;
334  // Win 32
335  case VER_PLATFORM_WIN32s:
336  so = 0;
337  break;
338  }
339  return so;
340 #else
341  return 0;
342 #endif
343 }
344 
345 
346 void txtfileEditCB(MOBJECT edit, char *text, char *ed)
347 {
348 
349  char buf1[255];
350  int i,flgbs,STRLEN;
351 
352 
353  sprintf(DFMT,"%s",text);
354 
355  flgbs = 0;
356  MObjectGetText(txtpath, buf1);
357  STRLEN = strlen(buf1);
358  i=1;
359  do
360  {
361  if(buf1[STRLEN - i] != 0x5C)
362  {
363  buf1[STRLEN - i] = 0;
364  i++;
365  }
366  else
367  {
368  flgbs = 1;
369  buf1[STRLEN - i] = 0;
370  }
371  }while (flgbs == 0);
372 
373 
374 
375 
376  ShowFileDrive(buf1, DFMT);
378 }
379 
380 
381 
382 void D_FInpFDCB(MOBJECT edit, char *buff, void *a)
383 {
384  int w = (int) a, er;
385  char str[255];
386 
387  switch(w)
388  {
389  // Path
390  case 0: er = _chdir(buff);
391  if(er == 0)
392  {
393  strcpy(DFNAME, buff);
394  if(str[strlen(DFNAME) - 1] != 0x5C)
395  strcat(DFNAME, "/");
397  }
398  break;
399  // File
400  case 1: strcpy(DFNAME, buff);
402  break;
403  }
404 }
405 
406 
407 MOBJECT MDCreateFM_Shell(int mod, int fmt)
408 {
409  MOBJECT _colform000;
410  MOBJECT _colform001;
411 // MOBJECT _label000;
412  MOBJECT tb2;
413  MOBJECT FM_Shell;
414  MOBJECT pb;
415  char buf[256];
416  int drive, curdrive = 0, sysop;
417  char curdir[_MAX_PATH];
418 
419  DFileType(fmt);
420 
421  _getcwd( BIL.DFILEM.WORKDIRECTORY, _MAX_PATH );
422  curdrive = _getdrive();
423 
424  sysop = WhoSys();
425 
426 
427 
428  FM_Shell = MCreateShell("File Manager", SF_MODAL);//0); //SF_NO_RESIZE|SF_NO_MAXIMIZE|SF_NO_MINIMIZE);
429  MObjectSetBackgroundRGB(FM_Shell, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
430 
431  _colform000 = MCreateColForm(FM_Shell);
432  MObjectAlign(_colform000, LEFT_ALIGN, TOP_ALIGN);
433  MObjectSetResize(_colform000, True, True);
434 
435  Row1 = MCreateRowForm(_colform000);
437  //MObjectSetBackgroundRGB(Row1, 149, 145, 153);
440 
441 
442 
443 /*
444  Row1 = MCreateRowForm(_colform000);
445  MObjectAlign(Row1, LEFT_ALIGN, TOP_ALIGN);
446  MObjectSetBackgroundRGB(Row1, 149, 145, 153);
447  MObjectSetResize(Row1, True, True);
448  MObjectSetCompositeWidth(Row1, 80);
449 
450  tb2 = MCreateTableForm(Row1, 2);
451  MFormSetSpacing(tb2, 1);
452  MTableFormSetColAlign(tb2, 0, LEFT_ALIGN);
453  MTableFormSetRowAlign(tb2, 1, TOP_ALIGN);
454  MObjectAlign(tb2, LEFT_ALIGN, TOP_ALIGN);
455  MObjectSetForegroundRGB(tb2, 149, 145, 153);
456  MObjectSetBackgroundRGB(tb2, 149, 145, 153);
457  MObjectSetResize(tb2, True, False);
458 */
459 
460  tb2 = MCreateTableForm(Row1, 2);
462  MObjectSetResize(tb2, True, True);
463 
464 
465 
466  for(drive = 1; drive <= 26; drive++)
467  {
468  sprintf( buf, "%c:", drive + 'A' - 1 );
469  DRV[drive] = MCreateRButton(tb2, buf, fmfont);
471 // MObjectSetCompositeWidth(DRV[drive], 150);
472  MRButtonSetCallback(DRV[drive], (OBJ_VALUE_CB) ChDriveCB, (void *) drive);
473  //controlla quali dischi sono presenti
474  if(_chdrive(drive))
475  MObjectSetUnsensitive(DRV[drive]);
476  }
477 
478  Row2 = MCreateRowForm(_colform000);
480  MObjectSetBackgroundRGB(Row2, 149, 145, 153);
482 
483 
484  FList = MCreateSList(Row2, fmfont, 255, 14, 37);
485 // MSListSetSortCallback(FList, strcmp);
486  MSListSetSortCallback(FList, stricmp);
491 // MSBLSetHead(FList, "Name " "Date " "Size");
492 
493 
494 /*
495  FList = MCreateSList(Row2, FIXED_SMALL, 256, 14, 37);
496  MObjectAlign(FList, LEFT_ALIGN, TOP_ALIGN);
497  MObjectSetForegroundRGB(FList, 255, 255, 255);
498  MObjectSetBackgroundRGB(FList, 0, 0, 0);
499  MObjectSetResize(FList, True, True);
500 */
501  _colform001 = MCreateColForm(FM_Shell);
502  MFormSetSpacing(_colform001, 1);
503  MObjectAlign(_colform001, LEFT_ALIGN, TOP_ALIGN);
504  MObjectSetResize(_colform001, True, False);
505 
506  tb1 = MCreateTableForm(_colform001, 3);
507  MFormSetSpacing(tb1, 1);
512 // MObjectSetForegroundRGB(tb1, 149, 145, 153);
515 
516  lbl = MCreateLabel(tb1, "Path:", fmfont);
519 // MObjectSetShadow(lbl, WS_SHADOW_IN, 2, 0);
521 
522  txtpath = MCreateClippedEdit(tb1, "", 255, 32, fmfont);
525  MEditSetActCallback(txtpath, D_FInpFDCB, (void *) 0);
528 
529  if(mod) // Open
530  {
531  pb = MCreatePButton(tb1, "Open", fmfont);
532  MPButtonSetCallback(pb, D_FMDoneCB, (void *) 0);
533  MObjectSetResize(pb, True, True);
535  }
536  else //Save as
537  {
538  pb = MCreatePButton(tb1, "Save As", fmfont);
539  MPButtonSetCallback(pb, D_FMDoneCB, (void *) 2);
540  MObjectSetResize(pb, True, True);
542 
543  }
544  lbl = MCreateLabel(tb1, "File:", fmfont);
549 
550  txtfile = MCreateClippedEdit(tb1, "", 255, 32, fmfont);
555  MEditSetActCallback(txtfile, D_FInpFDCB, (void *) 1);
556 
557 
558 
559  pb = MCreatePButton(tb1, "Cancel", fmfont);
560  MPButtonSetCallback(pb, D_FMDoneCB, (void *) 1);
562  MObjectSetResize(pb, True, True);
563 
564 
565 
566  MShellRealizeXY(FM_Shell, 0,0);
567 
568 
569  /* Restore original drive.*/
570  _chdrive( curdrive );
571  SELDRV = curdrive ;
572  if (sysop)
574  else
575  MRButtonActivate(DRV[SELDRV]);
576 
577 // sprintf(curdir,"%s%s",BIL.DFILEM.WORKDIRECTORY,"\\");
578  sprintf(curdir,"%s",BIL.DFILEM.WORKDIRECTORY);
579 
580  ShowFileDrive(curdir, DFMT);
581 
582  strcat(curdir,"\\");
583  MObjectSetText(txtpath, curdir);
584 
585 
586 // MEditSetActCallback(txtfile, txtfileEditCB, curdir);
587 
588 
590 
591 
592  FMINIT = 0;
593  MLoopWhileFlag(&FMINIT, 0);
594 
595  if(FMDONE)
596  {
597  FMINIT = 0;
598  MShellUnrealize(FM_Shell);
599  MShellDestroy(FM_Shell);
600 
601  }
602 
603 
604 
605  return FM_Shell;
606 
607 }
int FMDONE
Definition: DFileMan.c:35
#define FMAP
Definition: bildef.h:222
#define BOOL
Definition: DSCUD.H:100
void ChDriveCB(MOBJECT rb, MVALUE s, void *ad)
Definition: DFileMan.c:126
void MObjectSetBackgroundRGB(MOBJECT obj, int r, int g, int b)
#define WIN_NT
Define NT/XP/2000 and LINUX operating system (Realtime not possible).
Definition: dcldef.h:422
void DFMSelListCB(MOBJECT p, LIST_ACT *la, void *v)
Definition: DFileMan.c:175
MOBJECT lbl
Definition: DFileMan.c:42
short DB_FG_Plbl[3]
Foreground PASSIVE Label Colors.
INT32 MVALUE
Definition: Mguidefs.h:1422
#define FFID
Definition: bildef.h:226
void MObjectSetUnsensitive(MOBJECT obj)
List Item Activation.
Definition: Mguidefs.h:1179
MOBJECT MCreateLabel(MOBJECT parent, const char *text, MTFont font)
MOBJECT FList
Definition: DFileMan.c:40
void MObjectSetResize(MOBJECT obj, int resize_w, int resize_h)
#define FMOD
Definition: bildef.h:228
short DB_BG_Albl[3]
Background ACTIVE Label Colors.
#define False
Definition: Mguidefs.h:236
void MObjectAlign(MOBJECT obj, int h_align, int v_align)
MTFont fmfont
Definition: DFileMan.c:46
void MTableFormSetColAlign(MOBJECT form, int col, int al)
#define FCOL
Definition: bildef.h:227
char * MObjectGetText(MOBJECT obj, char *text)
char * item
Definition: Mguidefs.h:1181
MOBJECT MCreateClippedEdit(MOBJECT parent, const char *text, int len, int clip_len, MTFont font)
char DFMT[8]
Definition: DFileMan.c:30
void MShellUnrealize(MOBJECT obj)
void MObjectSetText(MOBJECT obj, const char *text)
#define FDAT
Definition: bildef.h:221
palette DPAL
Definition: 2DPlot.c:27
void MShellDestroy(MOBJECT obj)
MOBJECT MCreateTableForm(MOBJECT parent, int n_cols)
int FMINIT
Definition: DFileMan.c:34
MOBJECT Row1
Definition: DFileMan.c:37
void MRButtonSetCallback(MOBJECT button, OBJ_VALUE_CB cb, void *data)
MOBJECT MCreatePButton(MOBJECT parent, const char *text, MTFont font)
d_fileman DFILEM
Definition: bildef.h:257
MOBJECT DRV[26]
Definition: DFileMan.c:38
char * DFNAME
Definition: DFileMan.c:32
void ShowFileDrive(char *idir, char *ext)
Definition: DFileMan.c:62
#define CENTER_ALIGN
Definition: Mguidefs.h:917
int WhoSys(void)
Definition: DFileMan.c:306
MOBJECT Row2
Definition: DFileMan.c:39
void MSListClear(MOBJECT p)
#define HELV_SMALL
Definition: Mguidefs.h:881
void MEditSetActCallback(MOBJECT edit, OBJ_STRING_CB cb, void *data)
int MTFont
Definition: Mguidefs.h:175
MOBJECT MCreateSList(MOBJECT parent, MTFont font, int row_len, int nrow, int ncol)
#define SF_MODAL
Definition: Mguidefs.h:1019
void(* LIST_SEL_CB)(MOBJECT list, LIST_SEL *la, void *ad)
Definition: Mguidefs.h:1466
void MRButtonActivate(MOBJECT o)
char DBFILENAME[_MAX_PATH]
Definition: bildef.h:204
MOBJECT MDCreateFM_Shell(int mod, int fmt)
Definition: DFileMan.c:407
MOBJECT MCreateColForm(MOBJECT parent)
int SELDRV
Definition: DFileMan.c:33
void MShellRealizeXY(MOBJECT obj, int x, int y)
#define FRIS
Definition: bildef.h:225
void MSListSetSelectionCallback(MOBJECT obj, LIST_SEL_CB cb, void *data)
char * DDRIVE
Definition: DFileMan.c:29
#define _MAX_PATH
Definition: Dildef.h:202
MOBJECT MCreateShell(const char *title, int flags)
void DFMCloseCB(void)
Definition: DFileMan.c:267
short DB_BG[3]
Default Background Color.
MOBJECT MCreateRButton(MOBJECT parent, const char *text, MTFont font)
Function prototypes.
void MSListSetSortCallback(MOBJECT obj, STRCMP_CB cb)
static double p
Definition: SOLPOS.C:131
void DFileType(int i)
Definition: DFileMan.c:152
void MTableFormSetRowAlign(MOBJECT form, int row, int al)
void(* OBJ_VALUE_CB)(MOBJECT obj, MVALUE value, void *ad)
Definition: Mguidefs.h:1458
char * OLDPATH
Definition: DFileMan.c:31
void MLabelSetAlignment(MOBJECT p, int align)
MOBJECT tb1
Definition: DFileMan.c:41
Bortul Image Library Structure .
Definition: bildef.h:250
Types, structures and defines used in DCL libraries.
void MFormSetSpacing(MOBJECT p, int offset)
void MPButtonSetCallback(MOBJECT button, MGUI_CB cb, void *data)
char WORKDIRECTORY[_MAX_PATH]
Definition: bildef.h:202
#define FALL
Definition: bildef.h:224
void D_FInpFDCB(MOBJECT edit, char *buff, void *a)
Definition: DFileMan.c:382
MOBJECT txtpath
Definition: DFileMan.c:43
short DB_UnSel[3]
Unselected Buttons Colors.
void * MOBJECT
Definition: Mguidefs.h:192
#define True
Definition: Mguidefs.h:235
#define LEFT_ALIGN
Definition: Mguidefs.h:915
void D_FMDoneCB(MOBJECT shell, void *od, void *ad)
Definition: DFileMan.c:274
MOBJECT txtfile
Definition: DFileMan.c:44
int MSListAddItem(MOBJECT p, const char *item, void *data)
void MLoopWhileFlag(int *pflag, int value)
#define FELE
Definition: bildef.h:223
void MObjectSetForegroundRGB(MOBJECT obj, int r, int g, int b)
MOBJECT MCreateRowForm(MOBJECT parent)
void txtfileEditCB(MOBJECT edit, char *text, char *ed)
Definition: DFileMan.c:346
#define TOP_ALIGN
Definition: Mguidefs.h:918
bil BIL
Definition: DFileMan.c:27
#define FBIF
Definition: bildef.h:229
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:44:08 for DAS - Rel. 3.1.6 - 18/09/2017.