static int unpack_all_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); int method = RNA_enum_get(op->ptr, "method"); if (method != PF_KEEP) unpackAll(bmain, op->reports, method); /* XXX PF_ASK can't work here */ G.fileflags &= ~G_AUTOPACK; return OPERATOR_FINISHED; }
bool UnpackInfo::needUnpack(size_t index) const { if (unpackAll()) { return true; } for (size_t i = 0; i < _size; ++i) { if (_unpack[i] == index) { return true; } } return false; }
vespalib::string UnpackInfo::toString() const { vespalib::asciistream os; if (unpackAll()) { os << "full-unpack"; } else if (empty()) { os << "no-unpack"; } else { os << size_t(_unpack[0]); for (size_t i = 1; i < _size; ++i) { os << " " << size_t(_unpack[i]); } } return os.str(); }
UnpackInfo & UnpackInfo::insert(size_t index, bool unpack) { if (unpackAll()) { return *this; } for (size_t rp = 0; rp < _size; ++rp) { if (_unpack[rp] >= index) { if (_unpack[rp] == max_index) { forceAll(); return *this; } ++_unpack[rp]; } } if (unpack) { add(index); } return *this; }
UnpackInfo & UnpackInfo::remove(size_t index) { if (unpackAll()) { return *this; } size_t wp = 0; bool found_index = false; for (size_t rp = 0; rp < _size; ++rp) { if (_unpack[rp] == index) { found_index = true; } else if (_unpack[rp] > index) { _unpack[wp++] = (_unpack[rp] - 1); } else { _unpack[wp++] = _unpack[rp]; } } if (found_index) { --_size; } assert(wp == _size); return *this; }
int main(int argc, char *argv[]) { namespace po = boost::program_options; std::string privateKeyFile; std::string publicKeyFile; po::options_description general("General options"); general.add_options() ("help", "produce help message") ("generate-rsa,g", "generate RSA keys and save to public.key and private.key") ("publickey", po::value<std::string>(&publicKeyFile) ->default_value("public.key"), "path to publickey (default \"public.key\"") ("privatekey", po::value<std::string>(&privateKeyFile) ->default_value("private.key"), "path to private key (default \"private.key\""); po::options_description openContainer("Open existing container"); openContainer.add_options() ("open,o", po::value<std::string>(), "open existing container") ("unpack,u", po::value<std::string>(), "unpack selected files to directory") ("unpackAll,U", po::value<std::string>(), "unpack all files to directory") ("add,a", "add selected files"); po::options_description createContainer("Create new container"); createContainer.add_options() ("create,c", po::value<std::string>(), "create new container"); po::options_description hidden("Hidden options"); hidden.add_options() ("input-file", po::value<std::vector<std::string>>(), "input container file"); po::options_description cmdlineOptions; cmdlineOptions .add(general) .add(openContainer) .add(createContainer) .add(hidden); po::positional_options_description p; p.add("input-file", -1); po::variables_map vm; po::store(po::command_line_parser(argc, argv). options(cmdlineOptions).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << "Usage: CryptoContainer [options] <input or output files>" << std::endl; std::cout << general << "\n"; std::cout << openContainer << "\n"; std::cout << createContainer << "\n"; return 1; } if (vm.count("generate-rsa")) { std::cout << "Generating RSA keys" << std::endl; auto RSAKeys = cc::generateRSAKeys(); // Save public key std::cout << "Public key... "; cc::saveKeyToFile<CryptoPP::RSA::PublicKey>("public.key", RSAKeys.second); std::cout << "OK" << std::endl; // Save private key std::cout << "Private key... "; cc::saveKeyToFile<CryptoPP::RSA::PrivateKey>("private.key", RSAKeys.first); std::cout << "OK" << std::endl; return 1; } if (vm.count("create")) { std::cout << "Create container" << std::endl; if (!vm.count("input-file")) { std::cout << "Error: Need select input files" << std::endl; return -1; } if (!boost::filesystem::exists(publicKeyFile)) { std::cout << "Error: Public key doesn't exists" << std::endl; return -1; } if (boost::filesystem::is_directory(vm["create"].as<std::string>())) { std::cout << "Error: Path direct to directory" << std::endl; return -1; } auto publicKey = cc::loadKeyFromFile<CryptoPP::RSA::PublicKey>(publicKeyFile); auto container = cc::Container::openNewContainer(vm["create"].as<std::string>(), publicKey); if (!container) { std::cout << "invalid key or can't open file" << std::endl; return -1; } const auto pathsToPack = vm["input-file"].as<std::vector<std::string>>(); for (auto &input : pathsToPack) { container->addFileOrFolder(input); } std::cout << "Wait a while..." << std::endl; container->save(); std::cout << "Created " << vm["create"].as<std::string>() << " container" << std::endl; return 0; } if (vm.count("open")) { std::cout << "Open existed container" << std::endl; if (!boost::filesystem::exists(publicKeyFile)) { std::cout << "Error: Public key doesn't exists" << std::endl; return -1; } if (!boost::filesystem::exists(privateKeyFile)) { std::cout << "Error: Private key doesn't exists" << std::endl; return -1; } auto privateKey = cc::loadKeyFromFile<CryptoPP::RSA::PrivateKey>(privateKeyFile); auto publicKey = cc::loadKeyFromFile<CryptoPP::RSA::PublicKey>(publicKeyFile); auto container = cc::Container::openExistedContainer( vm["open"].as<std::string>(), publicKey, privateKey); if (!container) { std::cout << "Can't open container" << std::endl; return -1; } std::cout << "Wait a while..." << std::endl; if (vm.count("unpackAll")) { const std::string path = vm["unpackAll"].as<std::string>(); container->unpackAll(path); std::cout << "Unpacked all data to: " << path << std::endl; return 0; } else if (vm.count("unpack")) { const std::string targetPath = vm["unpack"].as<std::string>(); const auto pathsToUnpack = vm["input-file"].as<std::vector<std::string>>(); for (auto& path : pathsToUnpack) { std::cout << "Unpack: " << path << std::endl; container->unpack(path, targetPath); } std::cout << "Unpacked all data to: " << targetPath << std::endl; return 0; } else if (vm.count("add")) { const auto pathsToPack = vm["input-file"].as<std::vector<std::string>>(); for (auto &input : pathsToPack) { container->addFileOrFolder(input); } container->save(); std::cout << "Added" << std::endl; } else { std::cout << "Invalid command!" << std::endl; } } return 0; }
static Foo unpack(ConstPackIt first, ConstPackIt last) { Foo v; unpackAll(first, last, v.count, v.name, v.list); return std::move(v); }