Commit d8c34b99 authored by captainwong's avatar captainwong

add version_no.h; add choose exe feature for get_save_as_path

parent 58c8344c
#pragma once
#include <string>
#include <cstdlib>
#include <sstream>
#include <fstream>
namespace jlib {
struct version_no {
int major = 0;
int minor = 0;
int revision = 0;
int build = 0;
version_no& from_string(const std::string& s) {
std::sscanf(s.c_str(), "%d.%d.%d.%d", &major, &minor, &revision, &build);
if (major < 0) major = 0;
if (minor < 0) minor = 0;
if (revision < 0) revision = 0;
if (build < 0) build = 0;
return *this;
}
std::string to_string() const {
std::stringstream ss;
ss << major << "." << minor << "." << revision << "." << build;
return ss.str();
}
bool valid() {
return !(major == 0 && minor == 0 && revision == 0 && build == 0);
}
void reset() {
major = minor = revision = build = 0;
}
bool operator == (const version_no& ver) {
return major == ver.major
&& minor == ver.minor
&& revision == ver.revision
&& build == ver.build;
}
bool operator < (const version_no& ver) {
if (major > ver.major) return false;
if (minor > ver.minor) return false;
if (revision > ver.revision) return false;
if (build > ver.build) return false;
if (this->operator==(ver)) return false;
return true;
}
};
inline bool get_version_no_from_ini(version_no& ver, const std::string& ini_path) {
std::ifstream in(ini_path);
if (!in)return false;
std::stringstream is;
is << in.rdbuf();
version_no file_ver;
file_ver.from_string(is.str());
if (file_ver.valid()) {
ver = file_ver;
return true;
}
return false;
}
}
......@@ -46,7 +46,11 @@ inline bool get_file_open_dialog_result(std::wstring& path, HWND hWnd = nullptr)
}
inline bool get_save_as_dialog_path(std::wstring& path, const std::wstring& ext = L"", HWND hWnd = nullptr) {
inline bool get_save_as_dialog_path(std::wstring& path,
const std::wstring& ext = L"",
UINT cFileTypes = 0,
const COMDLG_FILTERSPEC *rgFilterSpec = nullptr,
HWND hWnd = nullptr) {
bool ok = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
......@@ -62,7 +66,17 @@ inline bool get_save_as_dialog_path(std::wstring& path, const std::wstring& ext
if (SUCCEEDED(hr)) {
pFileSave->SetDefaultExtension(ext.c_str());
if (!ext.empty()) {
pFileSave->SetDefaultExtension(ext.c_str());
}
if (cFileTypes != 0 && rgFilterSpec) {
pFileSave->SetFileTypes(cFileTypes, rgFilterSpec);
}
if (!hWnd) {
hWnd = ::GetDesktopWindow();
}
// Show the Open dialog box.
hr = pFileSave->Show(hWnd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment