コード例 #1
0
ファイル: posix_path.cpp プロジェクト: HiroyukiSeki/qtplatz
std::wstring
path::posix( const boost::filesystem::path& path )
{
    std::wstring temp = path.wstring();
    std::transform( temp.begin(), temp.end(), temp.begin(), detail::forslash<wchar_t>() );
    return temp;
}
コード例 #2
0
void CPsfRarArchive::Open(const boost::filesystem::path& filePath)
{
	Archive* arc(ConvertArchive(m_archive));
	arc->Open(filePath.wstring().c_str());
	arc->IsArchive(false);
	if(!arc->IsOpened())
	{
		throw std::runtime_error("Couldn't open archive.");
	}

	while(arc->ReadHeader() > 0)
	{
		if(arc->ShortBlock.HeaderType == HEAD_FILE)
		{
			if(!arc->IsArcDir())
			{
				FILEINFO fileInfo;
				fileInfo.name = string_cast<std::string>(arc->FileHead.FileName);
				boost::replace_all(fileInfo.name, "\\", "/");
				fileInfo.length = static_cast<unsigned int>(arc->FileHead.UnpSize);
				m_files.push_back(fileInfo);
			}
		}
		arc->SeekToNext();
	}
}
コード例 #3
0
std::string mf::utils::path_to_utf8(
        const boost::filesystem::path & path
    )
{
#ifdef _WIN32
        return mf::utils::wide_to_bytes(path.wstring());
#else
        return path.string();
#endif
}
コード例 #4
0
ファイル: DllMain.cpp プロジェクト: hjhong/YDWE
bool JumpListAddRecentTask(JumpList& jumpList, fs::path const& ydweDirectory, fs::path const& filePath)
{
	HRESULT hr = jumpList.AddTask(filePath.filename().c_str(), [&](CComPtr<IShellLinkW>& shellLinkPtr)
	{
		shellLinkPtr->SetPath((ydweDirectory / L"YDWE.exe").c_str());
		shellLinkPtr->SetArguments((L" -loadfile \"" + filePath.wstring() + L"\"").c_str());
		shellLinkPtr->SetDescription(filePath.c_str());
		shellLinkPtr->SetIconLocation((ydweDirectory / L"bin" / L"logo.ico").c_str(), 0);
	});

	return SUCCEEDED(hr);
}
コード例 #5
0
void CMainWindow::LoadArchive(const boost::filesystem::path& archivePath)
{
	try
	{
		m_playlist.Clear();
		m_playlistDiscoveryService.ResetRun();

		{
			auto archive(CPsfArchive::CreateFromPath(archivePath));
			unsigned int archiveId = m_playlist.InsertArchive(archivePath.wstring().c_str());

			for(const auto& fileInfo : archive->GetFiles())
			{
				auto pathToken = CArchivePsfStreamProvider::GetPathTokenFromFilePath(fileInfo.name);
				auto fileExtension = pathToken.GetExtension();
				if(CPlaylist::IsLoadableExtension(fileExtension))
				{
					CPlaylist::ITEM newItem;
					newItem.path = pathToken.GetWidePath();
					newItem.title = newItem.path;
					newItem.length = 0;
					newItem.archiveId = archiveId;
					unsigned int itemId = m_playlist.InsertItem(newItem);

					m_playlistDiscoveryService.AddItemInRun(pathToken, archivePath, itemId);
				}
			}
		}

		if(m_playlist.GetItemCount() > 0)
		{
			if(m_repeatMode == PLAYLIST_SHUFFLE)
			{
				unsigned int itemCount = m_playlist.GetItemCount();
				m_randomSeed = GetNextRandomNumber(m_randomSeed);
				m_currentPlaylistItem = (m_randomSeed % itemCount);
			}
			else
			{
				m_currentPlaylistItem = 0;
			}
			OnPlaylistItemDblClick(m_currentPlaylistItem);
		}
	}
	catch(const std::exception& except)
	{
		std::tstring errorString = _T("Couldn't load archive: \r\n\r\n");
		errorString += string_cast<std::tstring>(except.what());
		MessageBox(m_hWnd, errorString.c_str(), NULL, 16);
	}
}
コード例 #6
0
	std::wstring AbsoluteToLoksimRelativePath(const boost::filesystem::path& absolutePath, const boost::filesystem::path& l3dDir)
	{
		wstring upperAbs = boost::algorithm::to_upper_copy(absolutePath.wstring());
		wstring upperL3d = boost::algorithm::to_upper_copy(l3dDir.wstring());

		boost::algorithm::replace_all(upperAbs, L"/", L"\\");
		boost::algorithm::replace_all(upperL3d, L"/", L"\\");
		if (upperL3d[upperL3d.size() - 1] != '\\')
		{
			upperL3d.append(L"\\");
		}

		if (upperAbs.find(upperL3d) == 0)
		{
			wstring ret = absolutePath.wstring().substr(upperL3d.length());
			if (ret[ret.size() - 1] == '\\')
			{
				return ret.substr(0, ret.size() - 1);
			}
			return ret;
		}
		return absolutePath.wstring();
	}
コード例 #7
0
ファイル: TIFF.cpp プロジェクト: ome/ome-files-cpp
        /**
         * The constructor.
         *
         * Opens the TIFF using TIFFOpen().
         *
         * @param filename the filename to open.
         * @param mode the file open mode.
         */
        Impl(const boost::filesystem::path& filename,
             const std::string&             mode):
          tiff(),
          directoryCount(0)
        {
          Sentry sentry;

#ifdef _MSC_VER
          tiff = TIFFOpenW(filename.wstring().c_str(), mode.c_str());
#else
          tiff = TIFFOpen(filename.string().c_str(), mode.c_str());
#endif
          if (!tiff)
            sentry.error();
        }
コード例 #8
0
void CMainWindow::LoadSingleFile(const boost::filesystem::path& filePath)
{
	m_playlist.Clear();
	m_playlistDiscoveryService.ResetRun();

	//Insert a single item in the playlist
	{
		CPlaylist::ITEM item;
		item.path = filePath.wstring();
		m_playlist.InsertItem(item);
	}

	m_currentPlaylistItem = 0;
	OnPlaylistItemDblClick(m_currentPlaylistItem);
}
コード例 #9
0
	// Liefert vollen Pfad zum Local-Settings Ordner des Loksims (LOCAL_APPDATA/Loksim3D)
	// Erstellt Verzeichnis falls es nicht existiert
	std::wstring GetLocalSettingsPfad()
	{
		static boost::filesystem::path localAppDataPath;

		if (localAppDataPath.empty())
		{
			std::unique_ptr<wchar_t[]> confpath(new wchar_t[MAX_PATH]);
			if (S_OK == SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, confpath.get()))
			{
				localAppDataPath = boost::filesystem::path(confpath.get()) /  L"Loksim3D";
				if (!boost::filesystem::exists(localAppDataPath))
				{
					boost::filesystem::create_directories(localAppDataPath);
				}
			}
		}
		return localAppDataPath.wstring();
	}
コード例 #10
0
ファイル: GameScene.cpp プロジェクト: lythm/orb3d
bool GameScene::Save(boost::filesystem::path file)
{
	m_filepath = file;

	using namespace engine;
	DataStream_File stream;
	if(false == stream.OpenStream(file.wstring().c_str(), false))
	{
		return false;
	}

	if(false == m_pCore->GetScene()->Serialize(&stream))
	{
		return false;
	}

	stream.Close();

	return true;
}
コード例 #11
0
FileIO::Pointer FileIO::Open(
        boost::filesystem::path path,
        const std::string& open_mode,
        std::error_code * error
    )
{
    if (error)
        error->clear();

#if _WIN32
    std::wstring wide_open_mode = bytes_to_wide(open_mode);
    FILE* file_handle = _wfopen(
            path.wstring().c_str(),
            wide_open_mode.c_str()
        );
#else
    FILE* file_handle = fopen(
        path.string().c_str(),
        open_mode.c_str());
#endif

    if (file_handle != nullptr)
    {
        boost::system::error_code bec;
        uint64_t size_hint = boost::filesystem::file_size(path, bec);
        if (bec || size_hint == 0)
            size_hint = skDefaultBlockSize;

        return FileIO::Pointer(new FileIO(
                file_handle,
                size_hint
        ));
    }
    else
    {
        if ( error != nullptr )
            *error = std::error_code(errno, std::system_category());
        return FileIO::Pointer();
    }
}
コード例 #12
0
ファイル: filesystem.cpp プロジェクト: qtplatz/qtplatz
bool
filesystem::create( const boost::filesystem::path& filepath, size_t alloc, size_t page_size )
{
    if ( boost::filesystem::exists( filepath ) ) {
        boost::system::error_code ec;
        if ( ! boost::filesystem::remove( filepath, ec ) ) {
            return false;
        }
        filename_ = filepath.string();
    }

    db_.reset( new sqlite() );
    if ( db_->open( filepath.c_str() ) ) {

        filename_ = filepath.string();

        adfs::stmt sql( *db_ );

        sql.exec( "PRAGMA synchronous = OFF" );
        sql.exec( "PRAGMA journal_mode = MEMORY" );

        if ( page_size )
            sql.exec( ( boost::format( "PRAGMA page_size = %1%" ) % page_size ).str() );

        if ( alloc )
            internal::fs::prealloc( *db_, alloc );

        if ( internal::fs::format( *db_, filepath.wstring(), format_version_ ) ) {

            db_->set_fs_format_version( format_version_ );

            sql.exec( "PRAGMA FOREIGN_KEYS = ON" );
            return true;
        }
    }
    db_.reset();

    return false;
}
コード例 #13
0
ファイル: file_finder.cpp プロジェクト: strategist922/nscp
void file_finder::recursive_scan(file_filter::filter_result result, file_filter::filter_argument args, file_filter::filter_engine engine, boost::filesystem::path dir, bool recursive, int current_level) {
    if (!args->is_valid_level(current_level)) {
        if (args->debug) args->error->report_debug("Level deapth exausted: " + strEx::s::xtos(current_level));
        return;
    }
    WIN32_FIND_DATA wfd;

    DWORD fileAttr = GetFileAttributes(dir.wstring().c_str());
    if ((fileAttr == INVALID_FILE_ATTRIBUTES)&&(!recursive)) {
        args->error->report_error("Invalid file specified: " + dir.string());
    } else if (fileAttr == INVALID_FILE_ATTRIBUTES) {
        args->error->report_warning("Invalid file specified: " + dir.string());
    }
    if (args->debug) args->error->report_debug("Input is: " + dir.string() + " / " + strEx::s::xtos(fileAttr));

    if (!file_helpers::checks::is_directory(fileAttr)) {
        if (args->debug) args->error->report_debug("Found a file won't do recursive scan: " + dir.string());
        // It is a file check it an return (don't check recursively)
        file_helpers::patterns::pattern_type single_path = file_helpers::patterns::split_path_ex(dir.string());
        if (args->debug) args->error->report_debug("Path is: " + single_path.first.string());
        HANDLE hFind = FindFirstFile(dir.wstring().c_str(), &wfd);
        if (hFind != INVALID_HANDLE_VALUE) {
            boost::shared_ptr<file_filter::filter_obj> info = file_filter::filter_obj::get(args->now, wfd, single_path.first);
            if (engine)
                result->process(info, engine->match(info));
            else
                result->process(info, true);
            FindClose(hFind);
        } else {
            args->error->report_error("File was NOT found!");
        }
        return;
    }
    std::string file_pattern = dir.string() + "\\" + args->pattern;
    if (args->debug) args->error->report_debug("File pattern: " + file_pattern);
    HANDLE hFind = FindFirstFile(utf8::cvt<std::wstring>(file_pattern).c_str(), &wfd);
    if (hFind != INVALID_HANDLE_VALUE) {
        do {
            if (
                file_helpers::checks::is_directory(wfd.dwFileAttributes)
                && ( wcscmp(wfd.cFileName, _T(".")) != 0 || wcscmp(wfd.cFileName, _T("..")) != 0)
            )
                continue;
            boost::shared_ptr<file_filter::filter_obj> info = file_filter::filter_obj::get(args->now, wfd, dir);
            if (engine)
                result->process(info, engine->match(info));
            else
                result->process(info, true);
        } while (FindNextFile(hFind, &wfd));
        FindClose(hFind);
    }
    std::string dir_pattern = dir.string() + "\\*.*";
    if (args->debug) args->error->report_debug("File pattern: " + dir_pattern);
    hFind = FindFirstFile(utf8::cvt<std::wstring>(dir_pattern).c_str(), &wfd);
    if (hFind != INVALID_HANDLE_VALUE) {
        do {
            if (file_helpers::checks::is_directory(wfd.dwFileAttributes)) {
                if ( (wcscmp(wfd.cFileName, _T(".")) != 0) && (wcscmp(wfd.cFileName, _T("..")) != 0) )
                    recursive_scan(result, args, engine, dir / wfd.cFileName, true, current_level+1);
            }
        } while (FindNextFile(hFind, &wfd));
        FindClose(hFind);
    }
}
コード例 #14
0
void save(Archive& ar, const boost::filesystem::path& p, const unsigned int version)
{	
	std::wstring str = p.wstring();
	ar & BOOST_SERIALIZATION_NVP(str);
}
コード例 #15
0
ファイル: start_in_dir.hpp プロジェクト: pbondo/uniproxy
inline start_in_dir_<std::wstring> start_in_dir(const boost::filesystem::path &p)
{
    return start_in_dir_<std::wstring>(p.wstring());
}
コード例 #16
0
void CInspectorProperty_FilePath::SetValue(const boost::filesystem::path& value)
{
	m_edit.SetWindowText(value.wstring().c_str());
}
コード例 #17
0
	bool start(const boost::filesystem::path &root) override
 	{
		if (running_) {
			if (root_ == root) {
				return true;
			} else {
				return false;
			}
		}

		SECURITY_ATTRIBUTES sa = {};

		sa.nLength = sizeof(sa);
		sa.bInheritHandle = TRUE;

		cancel_event_ = ::CreateEventW(&sa, TRUE, FALSE, nullptr);

		if (cancel_event_ == nullptr) {
			return false;
		}

		HANDLE hstdout_read = nullptr;
		HANDLE hstdout_write = nullptr;
		HANDLE hstderr_write = nullptr;

		if (::CreatePipe(&hstdout_read, &hstdout_write, &sa, 0) == FALSE) {
			return false;
		}

		if (::DuplicateHandle(
			::GetCurrentProcess(), hstdout_write, ::GetCurrentProcess(), &hstderr_write,
			0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
		{
			::CloseHandle(hstdout_read);
			::CloseHandle(hstdout_write);
			return false;
		}

		if (::DuplicateHandle(
			::GetCurrentProcess(), hstdout_read, ::GetCurrentProcess(), &hstdout_,
			0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
		{
			::CloseHandle(hstdout_read);
			::CloseHandle(hstdout_write);
			::CloseHandle(hstderr_write);
			return false;
		}

		STARTUPINFOW si = {};

		si.cb = sizeof(STARTUPINFOW);
		si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		si.hStdOutput = hstdout_write;
		si.hStdError = hstderr_write;
		si.wShowWindow = SW_HIDE;

		PROCESS_INFORMATION pi = {};

		std::wstring command = L'\"' + (get_exe_path().remove_filename() / L"console-helper.exe").wstring();

		command += L"\" ";
		command += std::to_wstring(reinterpret_cast<std::uintptr_t>(cancel_event_));
		command += L' ';
		command += L"jupyter notebook --no-browser ";
		command += L"--notebook-dir=\"";
		command += root.wstring();
		command += L'\"';

		auto result = ::CreateProcessW(
			nullptr,
			const_cast<LPWSTR>(command.c_str()),
			nullptr,
			nullptr,
			TRUE,
			CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP,
			nullptr,
			nullptr,
			&si,
			&pi);

		::CloseHandle(hstdout_read);
		::CloseHandle(hstdout_write);
		::CloseHandle(hstderr_write);

		if (result == FALSE) {
			::CloseHandle(hstdout_);
			return false;
		}

		running_ = true;
		helper_process_ = pi.hProcess;

		char buf_array[256];
		DWORD read;

		std::string buf;

		const char *text = "The Jupyter Notebook is running at: ";
		auto text_len = ::strlen(text);

		for (;;) {
			if (::ReadFile(hstdout_, (LPVOID)buf_array, 255, &read, nullptr) == FALSE) {
				return false;
			}

			buf_array[read] = '\0';
			buf += buf_array;

			auto pos = buf.find(text);

			if (pos != std::string::npos) {
				pos += text_len;

				auto pos_end = buf.find_first_of("\r\n", pos);

				if (pos_end != std::string::npos) {
					auto s = buf.substr(pos + 7, pos_end - pos - 7);
					pos = s.find(':');
					pos_end = s.find('/', pos);
					auto aa = s.substr(pos + 1, pos_end - pos - 1);
					if (pos != std::string::npos && pos_end != std::string::npos) {
						try {
							port_ = static_cast<unsigned short>(std::stoul(s.substr(pos + 1, pos_end - pos - 1)));
						} catch (std::exception &e) {
							stop();
							throw e;
						}
					}
					break;
				}
			}
		}

		return port_ != 0;
	}
コード例 #18
0
int main(int argc, char* argv[])
{
	#pragma region Set locale for Chinese
	locale::global( g_locUTF8 );
	cout.imbue( g_locUTF8 );
	wcout.imbue( g_locUTF8 );
	clog.imbue(g_locUTF8);
	wclog.imbue(g_locUTF8);
	#pragma endregion

	#pragma region Variables
	// control by program options
	bool	bNoDLImage;
	bool	bOverWrite;
	bool	bFileIndex;
	bool	bTFileNameTitle;
	int		iRetryTimes;
	int		iIndexDigitals;
	string	sURL;
	string	sSearch;
	string	sReplace;
	FS::path	sDir;
	FS::path	sLogFile;
	FS::path	sOpenCC_Conf;

	// internal usage
	string		sEncode = "BIG5";
	FS::path	sExtBin = "Binary";
	FS::path	sImage = "images";
	#pragma endregion

	#pragma region Program Options
	{
		namespace BPO = boost::program_options;

		// define program options
		BPO::options_description bpoOptions( "Command Line Options" );
		bpoOptions.add_options()
			( "help,H",				BPO::bool_switch()->notifier( [&bpoOptions]( bool bH ){ if( bH ){ cout << bpoOptions << endl; exit(0); } } ),	"Help message" )
			( "url,U",				BPO::value(&sURL)->value_name("Web_Link"),										"The link of index page." )
			( "output,O",			BPO::value(&sDir)->value_name("output_dir")->default_value("."),				"Directory to save output files" )
			( "retry",				BPO::value(&iRetryTimes)->value_name("times")->default_value(100),				"HTTP retry times")
			( "s2c_conf",			BPO::value(&sOpenCC_Conf)->value_name("conf_file")->default_value("s2t.json"),	"SC to TC convertor configuration file")
			( "log",				BPO::value(&sLogFile)->value_name("log_file"),									"Log")
			( "search",				BPO::value(&sSearch)->value_name("string")->default_value(""),					"Search text in book name, use with --replace")
			( "replace",			BPO::value(&sReplace)->value_name("string")->default_value(""),					"Replace search trem with, use with --search")
			( "filename-as-title",	BPO::bool_switch(&bTFileNameTitle)->default_value(false),						"Use refined file-name as title in metadata")
			( "file_index",			BPO::bool_switch(&bFileIndex)->default_value(false),							"Add file index at the begin of file name")
			( "index_num",			BPO::value(&iIndexDigitals)->value_name("num")->default_value(2),				"Digitals of index (--file_index)")
			( "no_dl_image",		BPO::bool_switch(&bNoDLImage)->default_value(false),							"Not download image" )
			( "overwrite",			BPO::bool_switch(&bOverWrite)->default_value(false),							"Overwrite existed files" );

		// prase
		try
		{
			BPO::variables_map mVMap;
			BPO::store( BPO::command_line_parser( argc, argv ).options( bpoOptions ).allow_unregistered().run(), mVMap );
			BPO::notify( mVMap );
		}
		catch( BPO::error_with_option_name e )
		{
			cerr << e.what() << endl;
			cout << bpoOptions << endl;
			return 1;
		}
		catch( BPO::error e )
		{
			cerr << e.what() << endl;
			cout << bpoOptions << endl;
			return 1;
		}
		catch(exception e)
		{
			cerr << e.what() << endl;
			cout << bpoOptions << endl;
			return 2;
		}
	}
	#pragma endregion

	#pragma region Log System
	boost::shared_ptr< boost::log::core > core = boost::log::core::get();
	boost::shared_ptr< boost::log::sinks::text_ostream_backend > backend(new boost::log::sinks::text_ostream_backend());
	backend->add_stream(boost::shared_ptr< std::ostream >(&std::clog, boost::null_deleter()));
	backend->auto_flush(true);

	if (!sLogFile.empty())
	{
		boost::shared_ptr< std::ostream > fLog(new std::ofstream(sLogFile.string(), std::ofstream::app));
		fLog->imbue(g_locUTF8);
		backend->add_stream(fLog);
	}

	typedef boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend > sink_t;
	boost::shared_ptr< sink_t > sink(new sink_t(backend));
	sink->set_formatter(
		boost::log::expressions::stream << "[" << boost::log::trivial::severity << "]"
		<< "[" << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %T") << "] "
		<< boost::log::expressions::smessage
	);
	core->add_sink(sink);

	// setup common attributes
	boost::log::add_common_attributes();
	BOOST_LOG_TRIVIAL(trace) << "Strat log system";
	#pragma endregion

	#pragma region configuration by options
	// initial OpenCC
	try
	{
		g_pOpenCC = new opencc::SimpleConverter(sOpenCC_Conf.string());
	}
	catch (exception e)
	{
		BOOST_LOG_TRIVIAL(error) << "OpenCC Initialize error. " << e.what();
		return -1;
	}

	// external command refine
	wstring sExtPath = ( FS::current_path() / sExtBin ).wstring();
	g_sCalibre = sExtPath + g_sCalibre;

	// filename refine
	function<wstring(wstring)> funcNameRefine = [](wstring s){ return VertifyFilename(s); };
	if (sSearch != "")
	{
		funcNameRefine = [&sSearch, &sReplace, &sEncode](wstring s){
			wstring ss = VertifyFilename(s);
			boost::replace_all(ss, boost::locale::conv::to_utf<wchar_t>(sSearch, sEncode), boost::locale::conv::to_utf<wchar_t>(sReplace, sEncode));
			return ss;
		};
	}
	#pragma endregion

	try{
		HttpClient mClient;
		BOOST_LOG_TRIVIAL(info) << "Try to open: " << sURL;
		auto mURL = HttpClient::ParseURL(sURL);
		if (mURL)
		{
			Wenku8Cn mSite;
			if (mSite.CheckServer(mURL->first))
			{
				FS::path pathURL = FS::path(sURL).parent_path();

				int iTime = 0;
				boost::optional<wstring> rHtml;
				while (++iTime < iRetryTimes)
				{
					rHtml = mClient.ReadHtml(mURL->first, mURL->second);
					if (rHtml)
					{
						*rHtml = mSite.FilterHTML(*rHtml);
						break;
					}
				}

				if (!rHtml)
				{
					BOOST_LOG_TRIVIAL(error) << "Can't open URL: " << sURL;
					return -1;
				}

				auto vBooks = mSite.AnalyzeIndexPage(*rHtml);
				if (vBooks.first == L"")
				{
					BOOST_LOG_TRIVIAL(error) << "Can't find book information";
					return -1;
				}
				wstring sBN = ConvertS2T(vBooks.first);
				BOOST_LOG_TRIVIAL(trace) << "Strat to download novel: " << SConv( sBN );
				BOOST_LOG_TRIVIAL(info) << " >Found " << vBooks.second.size() << " books";

				// check directory
				g_sOutPath = sDir / VertifyFilename(sBN);
				if (!FS::exists(g_sOutPath))
					FS::create_directories(g_sOutPath);
				if (!bNoDLImage && !FS::exists(g_sOutPath / sImage))
					FS::create_directories(g_sOutPath / sImage);
				BOOST_LOG_TRIVIAL(trace) << "Output to " << g_sOutPath;

				// write
				int idxBook = 0;
				FS::current_path(g_sOutPath);
				for (BookIndex& rBook : vBooks.second)
				{
					wstring sBookName = ConvertS2T(rBook.m_sTitle);
					sBookName = funcNameRefine(sBookName);
					if (bFileIndex)
					{
						++idxBook;
						wstring wFmt = L"%0" + boost::lexical_cast<wstring>(iIndexDigitals) + L"d_%s";
						sBookName = (boost::wformat(wFmt) % idxBook % sBookName).str();
					}

					FS::path fnBook = sBookName + L".html";
					BOOST_LOG_TRIVIAL(trace) << " Start process book <" << fnBook << ">, with " << rBook.m_vChapter.size() << " chapters";

					// if file existed
					bool bToDownload = true;
					if (!bOverWrite && FS::exists(fnBook))
					{
						bToDownload = false;

						// read the index of existed html file
						wifstream fExistedFile(fnBook.wstring());
						wstring sTmp;
						int iCounter = 0;
						while (!fExistedFile.eof())
						{
							getline(fExistedFile, sTmp);
							if (sTmp == L"<NAV>")
							{
								while (!fExistedFile.eof())
								{
									getline(fExistedFile, sTmp);
									if (sTmp == L"</NAV>")
										break;
									else
										++iCounter;
								}
								break;
							}
						}
						fExistedFile.close();

						// re-download if chapter number is not equal
						if (iCounter != rBook.m_vChapter.size())
						{
							bToDownload = true;
							BOOST_LOG_TRIVIAL(info) << "  Chapter number is not equal, redownload. ( " << iCounter << " != " << rBook.m_vChapter.size() << " )";
						}
					}

					if (bToDownload)
					{
						wofstream oFile(fnBook.wstring());
						oFile.imbue(g_locUTF8);
						if (oFile.is_open())
						{
							wstring	sTitle = ConvertS2T(rBook.m_sTitle ),
									sAuthor = ConvertS2T(rBook.m_sAuthor );

							#pragma region HTML Header
							oFile << "<HTML>\n";
							oFile << "<HEAD>\n<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
							if (bTFileNameTitle)
								oFile << "<TITLE>" << sBookName << "</TITLE>\n";
							else
								oFile << "<TITLE>" << sTitle << "</TITLE>\n";
							oFile << "<META name=\"Author\" content=\"" << sAuthor << "\">\n</HEAD>\n";
							#pragma endregion

							#pragma region begining
							oFile << "<BODY>\n";
							oFile << "<H3 ALIGN=\"CENTER\">" << sTitle << "</H3>\n";
							oFile << "<H4 ALIGN=\"CENTER\">" << sAuthor << "</H4>\n";
							#pragma endregion

							#pragma region index
							oFile << "<A ID=\"INDEX\" /><HR>\n<NAV>\n";
							size_t idxChapter = 0;
							for (auto& rLink : rBook.m_vChapter)
							{
								rLink.first = ConvertS2T(rLink.first);
								oFile << "<p><a href=\"#CH" << ++idxChapter << "\">" << rLink.first << "</a><!-- " << rLink.second << " --></p>\n";
							}
							oFile << "</NAV>\n";
							#pragma endregion

							#pragma region content
							idxChapter = 0;
							for (auto& rLink : rBook.m_vChapter)
							{
								oFile << "<HR><A ID=\"CH" << ++idxChapter << "\" /><H4>" << rLink.first << "</H4>\n";
								BOOST_LOG_TRIVIAL(trace) << "  > " << SConv( rLink.second );

								int iBTime = 0;
								boost::optional<wstring> sHTML;
								while (++iBTime < iRetryTimes)
								{
									sHTML = mClient.ReadHtml(CheckLink(SConv(rLink.second), pathURL.string()));
									if (sHTML)
									{
										*sHTML = mSite.FilterHTML(*sHTML);
										break;
									}
								}
								if (sHTML)
								{
									if (!bNoDLImage)
									{
										auto vImg = mSite.FindAllImage(*sHTML);
										if (vImg.size() > 0)
										{
											cout << "      Found " << vImg.size() << " images\n";
											size_t uShift = 0;
											for (auto& rImg : vImg)
											{
												string sLink = CheckLink(SConv(rImg.second), pathURL.string());
												auto sFile = HttpClient::GetFilename(sLink);
												if (sFile)
												{
													BOOST_LOG_TRIVIAL(info) <<  "        " << *sFile;
													FS::path sImagePath = sImage / *sFile;

													bool bNeedDownload = true;
													if (FS::exists(sImagePath))
													{
														if (!bOverWrite)
														{
															auto uSize = FS::file_size(sImagePath);
															bNeedDownload = false;
														}
													}

													if (bNeedDownload)
													{
														int iTimes = 0;
														bool bOK = false;
														while (++iTimes < iRetryTimes)
														{
															BOOST_LOG_TRIVIAL(trace) << ".";
															bOK = mClient.GetBinaryFile(sLink, sImagePath.wstring());
															if (bOK)
																break;
														}
														if (bOK)
															BOOST_LOG_TRIVIAL(trace) << "OK";
														else
															BOOST_LOG_TRIVIAL(error) << "Image <" << *sFile << "> download error.";
													}
													else
														BOOST_LOG_TRIVIAL(trace) << "SKIP";

													sHTML->replace(uShift + rImg.first, rImg.second.size(), sImagePath.wstring());
													uShift += sImagePath.wstring().size() - rImg.second.size();
												}
											}
										}
									}
									oFile << ConvertS2T( mSite.GetChapterContent(*sHTML) );
								}
								else
								{
									BOOST_LOG_TRIVIAL(error) << "Can't read the page:" << SConv( rLink.second );
								}
							}
							oFile << "</BODY></HTML>\n";
							#pragma endregion

							oFile.close();
							BOOST_LOG_TRIVIAL(trace) << "  Start Convert";
							PostProcess(fnBook);
							BOOST_LOG_TRIVIAL(trace) << "  Book output finished";
						}
						else
						{
							BOOST_LOG_TRIVIAL(error) << " Can't open the file to output";
						}
					}
					else
					{
						BOOST_LOG_TRIVIAL(trace) << "  Skip this book.";
					}
				}
			}
		}
	}
	catch (exception e)
	{
		BOOST_LOG_TRIVIAL(fatal) << "Fatal error: " << e.what();
	}
	return 0;
}
コード例 #19
0
ファイル: PsfStreamProvider.cpp プロジェクト: 250394/Play-
CPsfPathToken CPhysicalPsfStreamProvider::GetPathTokenFromFilePath(const boost::filesystem::path& filePath)
{
	return filePath.wstring();
}
コード例 #20
0
 virtual void last_write_time_changed( const boost::filesystem::path& file )
 {
     stdcout << "handle change: " << file.wstring() << "\n";
 }
コード例 #21
0
void
tc_simple_wchar()
{
    using dotconf::Document ;
    using dotconf::Item ;
    utf8_to_oem conv( locale , console_cp_name );
    std::auto_ptr< const Document > doc_ptr ;
    try {
        const wchar_t * fname = L"Простой документ.conf" ;
        const fs::path test_path ( testdir_path / fname );
        const std::wstring testfile_str ( test_path.wstring() );
        BOOST_TEST_MESSAGE( i18n("Test file path") << ": " << conv(testfile_str) );
        doc_ptr.reset( new Document( testfile_str ) );
    } catch( const dotconf::SyntaxError & error ) {
        BOOST_FAIL( error.what() << " in position " << error.textpos );
    } catch( const std::exception & error ) {
        BOOST_FAIL( error.what() );
    } catch(...) {
        BOOST_FAIL( i18n("Unknown exception") );
    }
    BOOST_REQUIRE( 0 != doc_ptr.get() );
    const Document::Items_t & items = *doc_ptr;
    BOOST_REQUIRE( !items.empty() );
    Document::const_iterator it = items.begin();
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_comment("# Simple config file") );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("simpleParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value("simpleValue") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("strParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value("string value") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("textParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value
        ("Line 1 of big text param value...\n"
         "Line 2 of text parameter value...\n"
         "Line 3 (last) of text parameter value.") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("vectorParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value("value1") );
    BOOST_CHECK_EQUAL( *++it , Item::create_value("value2") );
    BOOST_CHECK_EQUAL( *++it , Item::create_value("value3") );
    BOOST_CHECK_EQUAL( *++it , Item::create_value("value4") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_node("Node1") );
    BOOST_CHECK( !items.has_child( it ) );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
} // tc_simple_wchar
コード例 #22
0
static void RunFragment(const boost::filesystem::path& path)
{
	std::wstring fileNameStr = path.wstring();
	const wchar_t* fileName = fileNameStr.c_str();

	rage::five::ResourceFlags flags;
	rage::five::BlockMap* bm = UnwrapRSC7(fileName, &flags);

	if (!bm)
	{
		wprintf(L"couldn't open input file %s...\n", path.filename().c_str());
		return;
	}

	rage::five::pgStreamManager::SetBlockInfo(bm);

	auto fragType = (rage::five::fragType*)bm->blocks[0].data;

	{
		std::vector<rage::five::rmcDrawable*> drawables;
		drawables.push_back(fragType->GetPrimaryDrawable());

		for (size_t i = 0; i < fragType->GetNumDrawables(); i++)
		{
			drawables.push_back(fragType->GetDrawable(i));
		}

		auto physLod = fragType->GetLodGroup()->GetLod(0);

		for (size_t i = 0; i < physLod->GetNumChildren(); i++)
		{
			drawables.push_back(physLod->GetChild(i)->GetDrawable());

			auto dr = physLod->GetChild(i)->GetDrawable2();

			if (dr)
			{
				drawables.push_back(physLod->GetChild(i)->GetDrawable2());
			}
		}

		for (auto& dr : drawables)
		{
			const auto& mp = dr->GetLodGroup().GetMaxPoint();

			if (dr->GetLodGroup().GetModel(1) != nullptr)
			{
				dr->GetLodGroup().SetModel(1, nullptr);
				dr->GetLodGroup().SetModel(2, nullptr);
			}
		}
	}

	auto p2 = path;
	p2 = p2.replace_extension(".new.yft");

	FILE* f = _wfopen(p2.wstring().c_str(), L"wb");

	if (!f)
	{
		printf("... couldn't open output file for writing.\n");
		return;
	}

	size_t outputSize = 0;

	bm->Save(162, [&](const void* d, size_t s)
	{
		fwrite(d, 1, s, f);

		outputSize += s;
	}, &flags);

	printf("written successfully - out size %d\n", outputSize);

	fclose(f);

	for (int i = 0; i < bm->physicalLen + bm->virtualLen; i++)
	{
		delete bm->blocks[i].data;
	}

	delete bm;
}