void MainMenu_OnFileOpen(HWND hwnd) { OPENFILENAME ofn; char filename[1024]; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ZeroMemory(filename, sizeof(filename)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Brightmoon Archive (*.dat)\0*.dat\0"; ofn.lpstrFile = filename; ofn.nMaxFile = sizeof filename; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST; if(!GetOpenFileName(&ofn)) return; ListView_SetItemCountEx(g_hListWnd, 0, LVSICF_NOINVALIDATEALL); g_listItems.clear(); if(!TryToOpenArchive(hwnd, filename)) { MessageBox(hwnd, "failed to open archive.", "error", MB_OK | MB_ICONSTOP); return; } do { MYLISTITEM item; PBGArchiveEntry *entry = g_archive.get()->GetEntry(); item.entry.reset(entry); std::string entryname(entry->GetEntryName()); std::vector<char> filename(entryname.begin(), entryname.end()); filename.push_back(0); PathStripPath(&filename[0]); item.column[0] = std::string(&filename[0]); std::vector<char> filepath(entryname.begin(), entryname.end()); filepath.push_back(0); PathRemoveFileSpecEx(&filepath[0]); item.column[1] = std::string(&filepath[0]); SHFILEINFO sfi; SHGetFileInfo(&filename[0], 0, &sfi, sizeof sfi, SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES); item.column[2] = std::string(sfi.szTypeName); char buffer[64]; wsprintf(buffer, "%d", entry->GetOriginalSize()); item.column[3] = std::string(buffer); long comp_ratio = MulDiv(entry->GetCompressedSize(), 100, entry->GetOriginalSize()); wsprintf(buffer, "%d", comp_ratio); item.column[4] = std::string(buffer); g_listItems.push_back(item); } while(g_archive.get()->EnumNext()); ListView_SetItemCountEx(g_hListWnd, g_listItems.size(), LVSICF_NOINVALIDATEALL); EnableMenuItem(g_hMenu, ID_FILE_CLOSE , MF_ENABLED); EnableMenuItem(g_hMenu, ID_FILE_EXTRACT, MF_ENABLED); EnableMenuItem(g_hMenu, 1, MF_BYPOSITION | MF_ENABLED); DrawMenuBar(hwnd); }
wstring_ty * sub_basename(sub_context_ty *scp, wstring_list_ty *arg) { wstring_ty *result; wstring_ty *suffix; wstring_ty *s1; long len; trace(("sub_basename()\n{\n")); switch (arg->nitems) { default: sub_context_error_set(scp, i18n("requires one or two arguments")); result = 0; break; case 2: result = entryname(arg->item[1]); break; case 3: s1 = entryname(arg->item[1]); suffix = arg->item[2]; len = (long)s1->wstr_length - (long)suffix->wstr_length; if ( len > 0 && !memcmp ( s1->wstr_text + len, suffix->wstr_text, suffix->wstr_length * sizeof(wchar_t) ) ) { result = wstr_n_from_wc(s1->wstr_text, len); wstr_free(s1); } else result = s1; break; } trace(("return %8.8lX;\n", (long)result)); trace(("}\n")); return result; }
void MainMenu_OnExtract(HWND hwnd) { BROWSEINFO bi; ZeroMemory(&bi, sizeof(BROWSEINFO)); bi.hwndOwner = hwnd; bi.lpszTitle = "Please choose a folder for extracted files."; bi.pidlRoot = CSIDL_DESKTOP; bi.ulFlags = BIF_RETURNONLYFSDIRS; LPITEMIDLIST lpidl = SHBrowseForFolder(&bi); if(!lpidl) return; char extractpath[1024]; SHGetPathFromIDList(lpidl, extractpath); CoTaskMemFree(lpidl); SetCurrentDirectory(extractpath); HWND hStatusDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_STATUS), hwnd, StatusDialog_WindowProc); SendDlgItemMessage(hStatusDlg, IDC_EDIT_STATUS, EM_SETSEL, 0, 0); ShowWindow(hStatusDlg, SW_SHOW); g_statuscancel = false; int index = -1; while((index = ListView_GetNextItem(g_hListWnd, index, LVNI_SELECTED)) != -1 && !g_statuscancel) { PBGArchiveEntry *entry = g_listItems[index].entry.get(); try { std::string entryname(entry->GetEntryName()); std::vector<char> outname(entryname.begin(), entryname.end()); outname.push_back(0); PathSlashToBackSlash(&outname[0]); std::vector<char> filepath(outname); PathRemoveFileSpecEx(&filepath[0]); if(filepath[0]) MakeSureDirectoryPathExists(&filepath[0]); int wlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, &outname[0], outname.size(), NULL, 0); std::vector<WCHAR> ws(wlen); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, &outname[0], outname.size(), &ws[0], ws.size()); ws.push_back(0); std::ofstream os(&ws[0], std::ios_base::binary); if(os.fail()) { throw std::exception(); } else { entry->Extract(os, ExtractCallback, (void *)hStatusDlg); } } catch(std::exception &e) { ExtractCallback("failed to create", (void *)hStatusDlg); ExtractCallback(entry->GetEntryName(), (void *)hStatusDlg); ExtractCallback("\r\n", (void *)hStatusDlg); } } DestroyWindow(hStatusDlg); }
/* ** 'discard' removes an item from the Basic stack, carrying out any ** work needed to undo the effects of that item */ static void discard(stackitem item) { basicstring temp; #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Drop '%s' entry at %p\n", entryname(item), basicvars.stacktop.bytesp); #endif switch(item) { case STACK_STRTEMP: temp = pop_string(); free_string(temp); break; case STACK_LOCAL: /* Restore local variable to its old value */ restore(1); break; case STACK_RETPARM: /* Deal with a 'return' parameter and restore local parameter */ restore_retparm(1); break; case STACK_GOSUB: /* Clear 'GOSUB' block from stack */ (void) pop_gosub(); break; case STACK_PROC: /* Clear 'PROC' block */ (void) pop_proc(); break; case STACK_FN: /* Clear 'FN' block */ (void) pop_fn(); break; case STACK_ERROR: /* Restore old Basic error handler */ basicvars.error_handler = pop_error(); break; case STACK_DATA: /* Restore old Basic data pointer */ basicvars.datacur = pop_data(); break; case STACK_LOCARRAY: /* Local numeric array */ basicvars.stacktop.bytesp+=entrysize[STACK_LOCARRAY]+basicvars.stacktop.locarraysp->arraysize; break; case STACK_LOCSTRING: /* Local string array */ discard_strings(basicvars.stacktop.bytesp+entrysize[STACK_LOCARRAY], basicvars.stacktop.locarraysp->arraysize); basicvars.stacktop.bytesp+=entrysize[STACK_LOCARRAY]+basicvars.stacktop.locarraysp->arraysize; break; default: if (item==STACK_UNKNOWN || item>=STACK_HIGHEST) error(ERR_BROKEN, __LINE__, "stack"); basicvars.stacktop.bytesp+=entrysize[item]; } }