short WPfile_selector( char *title, char *outpath, bool setpath, char *def_file, char *filter, char *outfile) /* A file selector under development. * * In: title = Window title/prompt * outpath = Initial path (and output) * setpath = TRUE if path may be changed * def_file = Default filename or "" * filter = Filter (any syntax accepted by ls) * * Out: *outfile = The file selected * *outpath = The path selected * * Return: 0 = Ok. * REJECT = Cancel. * * (C)2007-10-31 J.Kjellander * *******************************************************!*/ { char file[81],filett[81],uptt[81],newtt[81], butstr[JNLGTH],*fnptrs[MAX_FILES],fnbuf[FNBUF_SIZE], act_path[V3PTHLEN+1],new_path[V3PTHLEN+1],tmp[2*V3PTHLEN]; int iwin_x,iwin_y,iwin_dx,iwin_dy,i,scr_width,sb_x,sb_y, scr_height,pmtlen,butlen,buth,edtlen,edth, alt_x,alt_y,x1,y1,x2,y2; short status; DBint but_id,okey_id,help_id,reject_id,new_id,path_id, file_id,pmt_id,sb_id,up_id; unsigned int dum1,dum2; char *type[20],iconam[V3PTHLEN+1]; XrmValue value; WPIWIN *iwinpt; WPICON *icoptr; WPBUTT *butptr; WPEDIT *edtptr; /* ***Init static variables. */ altlst = fnptrs; /* ***Texts from the ini-file. */ if ( !WPgrst("varkon.input.up.tooltip",uptt) ) strcpy(uptt,"Up"); if ( !WPgrst("varkon.input.new.tooltip",newtt) ) strcpy(newtt,"New"); if ( !WPgrst("varkon.input.file",file) ) strcpy(file,"File:"); if ( !WPgrst("varkon.input.file.tooltip",filett) ) strcpy(filett,"file"); if ( !WPgrst("varkon.input.okey",okey) ) strcpy(okey,"Okey"); if ( !WPgrst("varkon.input.okey.tooltip",okeytt) ) strcpy(okeytt,""); if ( !WPgrst("varkon.input.reject",reject) ) strcpy(reject,"Reject"); if ( !WPgrst("varkon.input.reject.tooltip",rejecttt) ) strcpy(rejecttt,""); if ( !WPgrst("varkon.input.help",help) ) strcpy(help,"Help"); if ( !WPgrst("varkon.input.help.tooltip",helptt) ) strcpy(helptt,""); /* ***Window position. */ iwin_x = iwin_y = 20; if ( XrmGetResource(xresDB,"varkon.input.geometry", "Varkon.input.Geometry",type,&value) ) XParseGeometry((char *)value.addr,&iwin_x,&iwin_y,&dum1,&dum2); /* ***Air1 = Outer air. ***Air2 = Inner air. ***Air3 = List area air. */ air1 = 0.6*WPstrh(); air2 = 1.0*WPstrh(); air3 = 0.3*WPstrh(); /* ***Edit length and height. */ edtlen = 40*WPstrl("A"); edth = 1.6*WPstrh(); /* ***Get file list. */ strcpy(outfile,def_file); strcpy(act_path,outpath); make_filelist(act_path,filter,setpath,MAX_FILES,FNBUF_SIZE,fnptrs,fnbuf,&n_alts); /* ***Calculate column positions in list area etc. */ listarea_layout(); /* ***Height of list area (without optional slidebar). */ alth = WPstrh(); list_dy = N_LINES*(alth + air3) + air3; /* ***How long is the longest of the two prompts (File:/Filter:) ? */ pmtlen = 0; if ( WPstrl(file) > pmtlen ) pmtlen = WPstrl(file); if ( WPstrl(filter) > pmtlen ) pmtlen = WPstrl(filter); /* ***How long is the longest of Ok, Reject and Help (butlen) ? */ butlen = 0; if ( WPstrl(okey) > butlen ) butlen = WPstrl(okey); if ( WPstrl(reject) > butlen ) butlen = WPstrl(reject); if ( WPstrl(help) > butlen ) butlen = WPstrl(help); butlen *= 1.8; buth = 2*WPstrh(); /* ***The size of the screen. */ scr_width = DisplayWidth(xdisp,xscr); scr_height = DisplayHeight(xdisp,xscr); /* ***WPIWIN width, iwin_dx, the longest of a prompt + an edit ***or the three buttons Ok + Cancel + Help. */ iwin_dx = air1 + pmtlen + air1 + edtlen + air1; if ( iwin_dx < (3*butlen + 4*air1) ) iwin_dx = 3*butlen + 4*air1; /* ***Now that we know the width of the WPIWIN we can ***calculate the width of list area. */ list_dx = iwin_dx - 2*air1; /* ***Is a slidebar needed ? */ if ( colw_tot > list_dx ) sbar = TRUE; else sbar = FALSE; /* ***Add space for an optional slidebar. */ list_dy += WPstrh(); /* ***Now we can calculate the height of the WPIWIN, iwin_dy. */ iwin_dy = air1 + /* Air */ 32 + /* Up icon */ air2 + /* Air */ list_dy + /* List alternatives */ air2 + /* Air */ edth + /* File name edit */ air2 + /* Air */ edth + /* Filter edit */ air2 + /* Air over line */ air2 + /* Air under line */ buth + /* Ok, Cancel and Help */ air1; /* Air */ /* ***Create the WPIWIN window. */ WPposw(iwin_x,iwin_y,iwin_dx+10,iwin_dy+25,&iwin_x,&iwin_y); WPwciw((short)iwin_x,(short)iwin_y,(short)iwin_dx,(short)iwin_dy,title,&iwin_id); iwinpt = (WPIWIN *)wpwtab[(wpw_id)iwin_id].ptr; /* ***If setpath == TRUE it is allowed to traverse directories. ***In that case, create "up arrow" and "create directory" buttons ***followed by the path string. */ alt_x = air1; alt_y = air1; if ( setpath ) { strcpy(iconam,IGgenv(VARKON_ICO)); strcat(iconam,"/Varkon_uparrow.xpm"); WPmcic(iwin_id,alt_x,alt_y,1,iconam,WP_BGND1,WP_BGND1,&up_id); icoptr = (WPICON *)iwinpt->wintab[up_id].ptr; strcpy(icoptr->tt_str,uptt); alt_x += 32 + air1; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,36,36,(short)1, "New","New","",WP_BGND2,WP_FGND,&new_id); butptr = (WPBUTT *)iwinpt->wintab[new_id].ptr; strcpy(butptr->tt_str,newtt); alt_x += 32 + air1 + air1; alt_y = air1 + 12; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,WPstrl(act_path),WPstrh(),act_path,&path_id); } /* ***If setpath == FALSE, replace up/new buttons with "Path:". */ else { alt_x += air1; alt_y = air1 + 12; strcpy(tmp,"Path: "); strcat(tmp,act_path); WPcrlb((wpw_id)iwin_id,alt_x,alt_y,WPstrl(tmp),WPstrh(),tmp,&path_id); } /* ***The list area outline. */ list_x = alt_x = air1; list_y = alt_y += 16 + air2; x1 = alt_x; y1 = alt_y; x2 = alt_x + list_dx; y2 = y1; WPcreate_3Dline(iwin_id,x1,y1,x2,y2); y1 = alt_y + list_dy; y2 = y1; WPcreate_3Dline(iwin_id,x1,y1,x2,y2); x2 = x1; y2 = alt_y; WPcreate_3Dline(iwin_id,x1,y1,x2,y2); x1 = alt_x + list_dx; x2 = x1; WPcreate_3Dline(iwin_id,x1,y1,x2,y2); /* ***List area background = white. */ x1 = list_x + 1; y1 = list_y + 1; x2 = list_dx - 1; y2 = list_dy - 1; /*if ( sbar ) y2 -= WPstrh(); */ WPcreate_fillrect(iwin_id,x1,y1,x2,y2,WPgcol(0)); /* ***Optional list area slidebar. */ if ( sbar ) { alt_x = air1 + 1; butsiz = ((double)(list_dx)/(double)(colw_tot)*list_dx); WPcreate_slidebar(iwin_id,alt_x,alt_y+list_dy-WPstrh(),list_dx-2,WPstrh(), 0,butsiz,WP_SBARH,&sbptr); sb_id = sbptr->id.w_id; sbptr->cback = fssb_callback; } /* ***Remember the position where the slidebar lives. */ sb_x = alt_x; sb_y = alt_y; /* ***List area contents. */ nbuts = 0; fssb_callback(iwinpt); /* ***The file edit with prompt. */ alt_x = air1; alt_y += list_dy + air2; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,WPstrl(file),edth,file,&pmt_id); alt_x = air1 + pmtlen + air1; WPmced((wpw_id)iwin_id,alt_x,alt_y,edtlen,edth,(short)1, outfile,JNLGTH,&file_id); edtptr = (WPEDIT *)iwinpt->wintab[file_id].ptr; strcpy(edtptr->tt_str,filett); /* ***The filter with prompt. */ alt_x = air1; alt_y += edth + air2; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,WPstrl("Filter:"),edth,"Filter:",&pmt_id); alt_x = air1 + pmtlen + air1; WPcrlb((wpw_id)iwin_id,alt_x,alt_y,WPstrl(filter),edth,filter,&pmt_id); /* ***A 3D line. */ alt_x = iwin_dx/8; alt_y += edth + air2; WPcreate_3Dline(iwin_id,alt_x,alt_y,7*iwin_dx/8,alt_y); /* ***Ok, reject and help. */ alt_x = air1; alt_y += air2; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen,buth,(short)2, okey,okey,"",WP_BGND2,WP_FGND,&okey_id); butptr = (WPBUTT *)iwinpt->wintab[okey_id].ptr; strcpy(butptr->tt_str,okeytt); alt_x = air1 + butlen + air1; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen,buth,(short)2, reject,reject,"",WP_BGND2,WP_FGND,&reject_id); butptr = (WPBUTT *)iwinpt->wintab[reject_id].ptr; strcpy(butptr->tt_str,rejecttt); alt_x = iwin_dx - air1 - butlen; status = WPcrpb((wpw_id)iwin_id,alt_x,alt_y,butlen,buth,(short)2, help,help,"",WP_BGND2,WP_FGND,&help_id); butptr = (WPBUTT *)iwinpt->wintab[help_id].ptr; strcpy(butptr->tt_str,helptt); /* ***Display. */ WPwshw(iwin_id); /* ***WPwshw() gives focus to the first edit. ***Make sure that focus is on the file edit. */ edtptr = (WPEDIT *)iwinpt->wintab[file_id].ptr; WPfoed(edtptr,TRUE); /* ***Wait for action. */ status = 0; loop: WPwwtw(iwin_id,SLEVEL_V3_INP,&but_id); /* ***Using the up button is only allowed if ***path_edit = TRUE. */ if ( but_id == up_id ) { path_up(act_path,new_path); strcpy(act_path,new_path); goto update; } /* ***Create new directory. */ else if ( but_id == new_id ) { if ( create_directory(iwin_x + 50,iwin_y + 50,act_path) == 0 ) { goto update; } else goto loop; } /* ***Okey. */ else if ( but_id == okey_id || but_id == file_id ) { WPgted(iwin_id,file_id,outfile); if ( outfile[0] == '\0' ) { WPbell(); goto loop; } else { strcpy(outpath,act_path); status = 0; goto exit; } } /* ***Reject. */ else if ( but_id == reject_id ) { status = REJECT; goto exit; } /* ***Help. */ else if ( but_id == help_id ) { IGhelp(); goto loop; } /* ***An alternative selected. */ else { for ( i=0; i<nbuts; ++i ) { if ( but_id == alt_id[i] ) { butptr = (WPBUTT *)iwinpt->wintab[but_id].ptr; strcpy(butstr,butptr->stron); /* ***Enter a new directory. */ if ( butstr[strlen(butstr)-1] == '/' ) { strcat(act_path,butstr); goto update; } /* ***A file is selected. */ else { WPuped(iwin_id,file_id,butstr); goto loop; } } } goto loop; } /* ***Update the file list area after the path has changed or a new ***directory has been created. */ update: make_filelist(act_path,filter,setpath,MAX_FILES,FNBUF_SIZE,fnptrs,fnbuf,&n_alts); listarea_layout(); WPupbu(iwin_id,path_id,act_path,WPstrl(act_path)); /* ***Do we need to create or remove a slidebar ? */ if ( colw_tot > list_dx && !sbar ) { butsiz = ((double)(list_dx)/(double)(colw_tot)*list_dx); WPcreate_slidebar(iwin_id,sb_x,sb_y+list_dy-WPstrh(),list_dx-2,WPstrh(), 0,butsiz,WP_SBARH,&sbptr); sb_id = sbptr->id.w_id; sbptr->cback = fssb_callback; sbar = TRUE; } else if ( colw_tot <= list_dx && sbar ) { WPwdls(iwin_id,sb_id); sbar = FALSE; } /* ***Update the contents of the list window. */ fssb_callback(iwinpt); WPwshw(iwin_id); goto loop; /* ***The end. */ exit: WPwdel(iwin_id); return(status); }
BOOL init() { DWORD dwVersion = GetVersion(); // get source directory GetCurrentDirectory(sizeof(g_szSourceDir), g_szSourceDir); // load strings LoadString(g_hInstance, IDS_APPNAME, g_szAppName, sizeof(g_szAppName)); LoadString(g_hInstance, IDS_TARGET_GROUP, g_szTargetGroup, sizeof(g_szTargetGroup)); if (LOBYTE(LOWORD(dwVersion)) < 4) { MessageBox(HWND_DESKTOP, "This install program needs Windows 4.0 or later", g_szAppName, MB_OK); return FALSE; } if ( (HIWORD(dwVersion) & 0x8000) == 0) is_winnt = TRUE; cinst.SetMessageFunction(message_box); #define MAXCMDTOKENS 128 int argc; LPSTR argv[MAXCMDTOKENS]; LPSTR p; char command[256]; char *args; char *d, *e; p = GetCommandLine(); argc = 0; args = (char *)malloc(lstrlen(p)+1); if (args == (char *)NULL) return 1; // Parse command line handling quotes. d = args; while (*p) { // for each argument if (argc >= MAXCMDTOKENS - 1) break; e = d; while ((*p) && (*p != ' ')) { if (*p == '\042') { // Remove quotes, skipping over embedded spaces. // Doesn't handle embedded quotes. p++; while ((*p) && (*p != '\042')) *d++ =*p++; } else *d++ = *p; if (*p) p++; } *d++ = '\0'; argv[argc++] = e; while ((*p) && (*p == ' ')) p++; // Skip over trailing spaces } argv[argc] = NULL; if (strlen(argv[0]) == 0) { GetModuleFileName(g_hInstance, command, sizeof(command)-1); argv[0] = command; } if (argc > 2) { // Probably creating filelist.txt return make_filelist(argc, argv); } // check if batch mode requested // get location of target directory from command line as argv[1] if (argc == 2) { strncpy(g_szTargetDir, argv[1], sizeof(g_szTargetDir)); g_bBatch = TRUE; if (is_winnt) g_bAllUsers = TRUE; } if (g_bBatch) { if (!install_all()) { // display log showing error g_bBatch = FALSE; g_hWndText = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_TEXTWIN), (HWND)HWND_DESKTOP, TextWinDlgProc, (LPARAM)NULL); gs_addmess_update(); } return TRUE; } // Interactive setup if (!GetProgramFiles(g_szTargetDir)) strcpy(g_szTargetDir, "C:\\Program Files"); strcat(g_szTargetDir, "\\"); LoadString(g_hInstance, IDS_TARGET_DIR, g_szTargetDir+strlen(g_szTargetDir), sizeof(g_szTargetDir)-strlen(g_szTargetDir)); // main dialog box g_hMain = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_MAIN), (HWND)NULL, MainDlgProc, (LPARAM)NULL); // centre dialog on screen int width = GetSystemMetrics(SM_CXFULLSCREEN); int height = GetSystemMetrics(SM_CYFULLSCREEN); RECT rect; GetWindowRect(g_hMain, &rect); MoveWindow(g_hMain, (width - (rect.right - rect.left))/2, (height - (rect.bottom - rect.top))/2, (rect.right - rect.left), (rect.bottom - rect.top), FALSE); // initialize targets cinst.SetMessageFunction(message_box); if (!cinst.Init(g_szSourceDir, "filelist.txt")) return FALSE; SetDlgItemText(g_hMain, IDC_TARGET_DIR, g_szTargetDir); SetDlgItemText(g_hMain, IDC_TARGET_GROUP, g_szTargetGroup); SetDlgItemText(g_hMain, IDC_PRODUCT_NAME, cinst.GetUninstallName()); ShowWindow(g_hMain, SW_SHOWNORMAL); return (g_hMain != (HWND)NULL); /* success */ }
BOOL init() { DWORD dwVersion = GetVersion(); // get source directory if (LOBYTE(LOWORD(dwVersion)) < 4) { MessageBox(HWND_DESKTOP, "This install program needs Windows 4.0 or later", g_szAppName, MB_OK); return FALSE; } #define MAXCMDTOKENS 128 int argc; LPSTR argv[MAXCMDTOKENS]; LPSTR p; char *args; char *d, *e; p = GetCommandLine(); argc = 0; args = (char *)malloc(lstrlen(p)+1); if (args == (char *)NULL) return 1; // Parse command line handling quotes. d = args; while (*p) { // for each argument if (argc >= MAXCMDTOKENS - 1) break; e = d; while ((*p) && (*p != ' ')) { if (*p == '\042') { // Remove quotes, skipping over embedded spaces. // Doesn't handle embedded quotes. p++; while ((*p) && (*p != '\042')) *d++ =*p++; } else *d++ = *p; if (*p) p++; } *d++ = '\0'; argv[argc++] = e; while ((*p) && (*p == ' ')) p++; // Skip over trailing spaces } argv[argc] = NULL; if (argc > 2) { // Probably creating filelist.txt return make_filelist(argc, argv); } return 0; }