void WizNoteManager::downloadTemplatePurchaseRecord() { //下载用户购买的模板列表 WizExecuteOnThread(WIZ_THREAD_NETWORK, [=]() { WizEnsurePathExists(Utils::WizPathResolve::customNoteTemplatesPath()); // QNetworkAccessManager manager; QString url = WizCommonApiEntry::asServerUrl() + "/a/templates/record?token=" + WizToken::token(); // qDebug() << "get templates record from url : " << url; // QByteArray ba; { QNetworkReply* reply = manager.get(QNetworkRequest(url)); WizAutoTimeOutEventLoop loop(reply); loop.exec(); // if (loop.error() != QNetworkReply::NoError || loop.result().isEmpty()) return; ba = loop.result(); QString jsonFile = Utils::WizPathResolve::wizTemplatePurchaseRecordFile(); std::ofstream recordFile(jsonFile.toUtf8().constData(), std::ios::out | std::ios::trunc); recordFile << ba.constData(); } }); }
bool ImportFile::keyPressEvent(QKeyEvent *event) { if (GetFocusWidget()->keyPressEvent(event)) return true; bool handled = false; QStringList actions; handled = GetMythMainWindow()->TranslateKeyPress("Archive", event, actions); for (int i = 0; i < actions.size() && !handled; i++) { QString action = actions[i]; handled = true; if (action == "MENU") { showMenu(); } else if (action == "PLAY") { playFile(); } else if (action == "RECORD") { recordFile(); } else if (action == "EDIT") { editFileMetadata(); } else if (action == "INFO") { Init(); } else handled = false; } if (!handled && MythScreenType::keyPressEvent(event)) handled = true; return handled; }
void checkFileAreas(const std::string& datadir, bool verbose) { vector<directoryrec> directories; { DataFile<directoryrec> file(datadir, DIRS_DAT); if (!file) { // TODO(rushfan): show error? return; } if (!file.ReadVector(directories)) { // TODO(rushfan): show error? return; } } LOG(INFO) << "Checking " << directories.size() << " directories."; for (size_t i = 0; i < directories.size(); i++) { if (!(directories[i].mask & mask_cdrom) && !(directories[i].mask & mask_offline)) { File dir(directories[i].path); if (checkDirExists(dir, directories[i].name)) { LOG(INFO) << "Checking directory: " << directories[i].name; string filename = StrCat(directories[i].filename, ".dir"); File recordFile(datadir, filename); if (recordFile.Exists()) { if (!recordFile.Open(File::modeReadWrite | File::modeBinary)) { LOG(INFO) << "Unable to open:" << recordFile.full_pathname(); } else { unsigned int numFiles = recordFile.GetLength() / sizeof(uploadsrec); uploadsrec upload; recordFile.Read(&upload, sizeof(uploadsrec)); if (upload.numbytes != numFiles) { LOG(INFO) << "Corrected # of files in: " << directories[i].name; upload.numbytes = numFiles; recordFile.Seek(0L, File::seekBegin); recordFile.Write(&upload, sizeof(uploadsrec)); } if (numFiles >= 1) { ext_desc_rec *extDesc = nullptr; unsigned int recNo = 0; string filenameExt = directories[i].filename; filenameExt.append(".ext"); File extDescFile(datadir, filenameExt); if (extDescFile.Exists()) { if (extDescFile.Open(File::modeReadWrite | File::modeBinary)) { extDesc = (ext_desc_rec *)malloc(numFiles * sizeof(ext_desc_rec)); size_t offs = 0; while (offs < (unsigned long)extDescFile.GetLength() && recNo < numFiles) { ext_desc_type ed; extDescFile.Seek(offs, File::seekBegin); if (extDescFile.Read(&ed, sizeof(ext_desc_type)) == sizeof(ext_desc_type)) { strcpy(extDesc[recNo].name, ed.name); extDesc[recNo].offset = offs; offs += ed.len + sizeof(ext_desc_type); recNo++; } } } extDescFile.Close(); } for (size_t fileNo = 1; fileNo < numFiles; fileNo++) { bool modified = false; recordFile.Seek(sizeof(uploadsrec) * fileNo, File::seekBegin); recordFile.Read(&upload, sizeof(uploadsrec)); bool extDescFound = false; for (unsigned int desc = 0; desc < recNo; desc++) { if (strcmp(upload.filename, extDesc[desc].name) == 0) { extDescFound = true; } } if (extDescFound && ((upload.mask & mask_extended) == 0)) { upload.mask |= mask_extended; modified = true; LOG(INFO) << "Fixed (added) extended description for: " << upload.filename; } else if (!extDescFound && (upload.mask & mask_extended)) { upload.mask &= ~mask_extended; modified = true; LOG(INFO) << "Fixed (removed) extended description for: " << upload.filename; } File file(directories[i].path, Unalign(upload.filename)); if (strlen(upload.filename) > 0 && file.Exists()) { if (file.Open(File::modeReadOnly | File::modeBinary)) { if (verbose) { LOG(INFO) << "Checking file: " << file.full_pathname(); } if (upload.numbytes != (unsigned long)file.GetLength()) { upload.numbytes = file.GetLength(); modified = true; LOG(INFO) << "Fixed file size for: " << upload.filename; } file.Close(); } else { LOG(INFO) << "Unable to open file '" << file.full_pathname() << "', error:" << file.GetLastError(); } } if (modified) { recordFile.Seek(sizeof(uploadsrec) * fileNo, File::seekBegin); recordFile.Write(&upload, sizeof(uploadsrec)); } } if (extDesc != nullptr) { free(extDesc); extDesc = nullptr; } } recordFile.Close(); } } else { LOG(INFO) << "Directory '" << directories[i].name << "' missing file: " << recordFile.full_pathname(); } } } else if (directories[i].mask & mask_offline) { LOG(INFO) << "Skipping directory '" << directories[i].name << "' [OFFLINE]"; } else if (directories[i].mask & mask_cdrom) { LOG(INFO) << "Skipping directory '" << directories[i].name << "' [CDROM]"; } else { LOG(INFO) << "Skipping directory '" << directories[i].name << "' [UNKNOWN MASK]"; } } }
int main(int argc, char** argv) { boost::timer::auto_cpu_timer t; std::string description = std::string("Compute the clique scores for a Markov network from a csv file. Example usage: ") + argv[0] + " iris.csv iris.css"; po::options_description desc(description); desc.add_options() ("input", po::value<std::string > (&inputFile)->required(), "The input file. First positional argument.") ("output", po::value<std::string > (&outputFile)->required(), "The output file. Second positional argument.") ("delimiter,d", po::value<char> (&delimiter)->required()->default_value(','), "The delimiter of the input file.") ("constraints,c", po::value<std::string > (&constraintsFile), "The file specifying constraints on the scores. Constraints are currently unsupported.") ("rMin,m", po::value<int> (&rMin)->default_value(5), "The minimum number of records in the AD-tree nodes.") ("function,f", po::value<std::string > (&sf)->default_value("BDeu"), "The scoring function to use.") ("sfArgument,a", po::value<std::string> (&sfArgument)->default_value("1.0"), "The equivalent sample size, if BDeu is used.") ("maxClique,m", po::value<int> (&maxClique)->default_value(0), "The maximum number of variables in any clique (inclusive). A value less than 1 means no limit.") ("threads,t", po::value<int> (&threadCount)->default_value(1), "The number of separate threads to use for score calculations. Multi-threading is currently unsupported.") ("time,r", po::value<int> (&runningTime)->default_value(-1), "The maximum amount of time to use. A value less than 1 means no limit.") ("hasHeader,s", "Add this flag if the first line of the input file gives the variable names.") ("help,h", "Show this help message.") ; po::positional_options_description positionalOptions; positionalOptions.add("input", 1); positionalOptions.add("output", 1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc) .positional(positionalOptions).run(), vm); if (vm.count("help") || argc == 1) { std::cout << desc; return 0; } po::notify(vm); hasHeader = vm.count("hasHeader"); // no multithreading right now threadCount = 1; if (threadCount < 1) { threadCount = 1; } printf("URLearning, Markov Network Score Calculator\n"); printf("Input file: '%s'\n", inputFile.c_str()); printf("Output file: '%s'\n", outputFile.c_str()); printf("Delimiter: '%c'\n", delimiter); printf("Constraints file: '%s'\n", constraintsFile.c_str()); printf("r_min: '%d'\n", rMin); printf("Scoring function: '%s'\n", sf.c_str()); printf("Scoring function argument: '%s'\n", sfArgument.c_str()); printf("Maximum clique size: '%d'\n", maxClique); printf("Threads: '%d'\n", threadCount); printf("Running time (per variable): '%d'\n", runningTime); printf("Has header: '%s'\n", (hasHeader ? "true" : "false")); printf("Parsing input file.\n"); datastructures::RecordFile recordFile(inputFile, delimiter, hasHeader); recordFile.read(); printf("Initializing data specifications.\n"); network.initialize(recordFile); printf("Creating AD-tree.\n"); scoring::ADTree *adTree = new scoring::ADTree(rMin); adTree->initialize(network, recordFile); adTree->createTree(); if (maxClique > network.size() || maxClique < 1) { maxClique = network.size(); } scoring::Constraints *constraints = NULL; if (constraintsFile.length() > 0) { constraints = scoring::parseConstraints(constraintsFile, network); } scoringFunction = scoring::createMarkovNetworkScoringFunction(sf, sfArgument, network, adTree, constraints); std::vector<boost::thread*> threads; for (int thread = 0; thread < threadCount; thread++) { boost::thread *workerThread = new boost::thread(scoringThread, thread); threads.push_back(workerThread); } for (auto it = threads.begin(); it != threads.end(); it++) { (*it)->join(); } // concatenate all of the files together std::ofstream out(outputFile, std::ios_base::out | std::ios_base::binary); // first, the header information std::string header = "META css_version = 0.1\nMETA input_file=" + inputFile + "\nMETA num_records=" + TO_STRING(recordFile.size()) + "\n"; header += "META clique_limit=" + TO_STRING(maxClique) + "\nMETA score_type=" + sf + "\nMETA score_argument=" + TO_STRING(sfArgument) + "\n\n"; out.write(header.c_str(), header.size()); // now, write all of the variable information for (int variable = 0; variable < network.size(); variable++) { datastructures::Variable *var = network.get(variable); std::string variableHeader = "VAR " + var->getName() + "\n"; variableHeader += "META arity=" + TO_STRING(var->getCardinality()) + "\n"; variableHeader += "META values="; for (int i = 0; i < var->getCardinality(); i++) { variableHeader += var->getValue(i).c_str(); variableHeader += " "; } variableHeader += "\n"; out.write(variableHeader.c_str(), variableHeader.size()); } for (int thread = 0; thread < threadCount; thread++) { std::string threadFilename = outputFile + "." + TO_STRING(thread); std::ofstream threadFile(threadFilename, std::ios_base::in | std::ios_base::binary); out << threadFile.rdbuf(); threadFile.close(); // and remove the variable file remove(threadFilename.c_str()); } out.close(); }