Commit fbe78c85 authored by captainwong's avatar captainwong

test version

parent 03073231
#pragma once
#include "../base/config.h"
#include <string>
#include <cstdlib>
#include <sstream>
......@@ -15,30 +16,43 @@ struct Version {
int revision = 0;
int build = 0;
Version& fromString(const std::string& s) {
Version() = default;
Version(int major, int minor, int revision, int build)
: major(major), minor(minor), revision(revision), build(build) {}
Version(const std::string& s) { _fromString(s); }
Version& fromString(const std::string& s) { _fromString(s); return *this; }
bool valid() { return !(major == 0 && minor == 0 && revision == 0 && build == 0); }
void reset() { major = minor = revision = build = 0; }
bool _fromString(const std::string& s) {
if (std::sscanf(s.c_str(), "%d.%d.%d.%d", &major, &minor, &revision, &build) != 4) {
reset(); return *this;
reset(); return false;
}
if (major < 0) major = 0;
if (minor < 0) minor = 0;
if (revision < 0) revision = 0;
if (build < 0) build = 0;
return *this;
if (major < 0) major = 0; if (minor < 0) minor = 0;
if (revision < 0) revision = 0; if (build < 0) build = 0;
return true;
}
std::string toString() const {
return std::to_string(major) + "."
+ std::to_string(minor) + "."
+ std::to_string(revision) + "."
+ std::to_string(build);
return std::to_string(major) + "." +
std::to_string(minor) + "." +
std::to_string(revision) + "." +
std::to_string(build);
}
bool valid() {
return !(major == 0 && minor == 0 && revision == 0 && build == 0);
bool fromFile(const std::string& path) {
std::ifstream in(path); if (!in) return false;
std::stringstream is; is << in.rdbuf();
Version file_ver(is.str());
if (file_ver.valid()) { *this = file_ver; return true; }
return false;
}
void reset() {
major = minor = revision = build = 0;
bool toFile(const std::string& path) {
std::ofstream out(path); if (!out) { return false; }
auto str = toString(); out.write(str.data(), str.size());
return true;
}
bool operator == (const Version& ver) {
......@@ -56,6 +70,15 @@ struct Version {
if (this->operator==(ver)) return false;
return true;
}
bool operator > (const Version& 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;
}
};
struct UpdateInfo {
......@@ -69,18 +92,4 @@ struct UpdateInfoText {
std::string dllink = {};
};
inline bool getVersionFromFile(const std::string& file_path, Version& version) {
std::ifstream in(file_path);
if (!in)return false;
std::stringstream is;
is << in.rdbuf();
Version file_ver;
file_ver.fromString(is.str());
if (file_ver.valid()) {
version = file_ver;
return true;
}
return false;
}
}
#pragma once
#include <algorithm>
#include <Windows.h>
#include <ShlObj.h>
#include <string>
#include <algorithm>
#pragma comment(lib, "Shell32.lib")
namespace jlib {
namespace win32 {
......@@ -19,14 +16,18 @@ inline std::string getExePathA() {
char path[1024] = { 0 }; ::GetModuleFileNameA(nullptr, path, 1024); return path;
}
inline std::wstring getExeFolderPath() {
auto path = getExePath(); auto pos = path.find_last_of(L"\\/"); return path.substr(0, pos);
inline std::wstring getFolder(const std::wstring& path) {
auto pos = path.find_last_of(L"\\/"); return pos != path.npos ? path.substr(0, pos) : path;
}
inline std::string getExeFolderPathA() {
auto path = getExePathA(); auto pos = path.find_last_of("\\/"); return path.substr(0, pos);
inline std::string getFolder(const std::string& path) {
auto pos = path.find_last_of("\\/"); return pos != path.npos ? path.substr(0, pos) : path;
}
inline std::wstring getExeFolderPath() { return getFolder(getExePath()); }
inline std::string getExeFolderPathA() { return getFolder(getExePathA()); }
static constexpr const wchar_t* DEFAULT_PATH_FILTERW = L"\\/:*?\"<>| ";
static constexpr const char* DEFAULT_PATH_FILTER = "\\/:*?\"<>| ";
......@@ -79,5 +80,40 @@ inline std::string getTempFileNameA(const std::string& pre = "JLIB") {
return getTempFileName(getTempPathA(), pre);
}
inline bool folderExists(const std::wstring& folderPath) {
DWORD dwAttrib = ::GetFileAttributesW(folderPath.data());
return (dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
}
inline bool folderExists(const std::string& folderPath) {
DWORD dwAttrib = ::GetFileAttributesA(folderPath.data());
return (dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
}
inline bool fileExists(const std::wstring& filePath) {
DWORD dwAttrib = ::GetFileAttributesW(filePath.data());
return (dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
}
inline bool fileExists(const std::string& filePath) {
DWORD dwAttrib = ::GetFileAttributesA(filePath.data());
return (dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
}
inline bool createDirectory(const std::wstring& path) {
return ::CreateDirectoryW(path.data(), nullptr) ? true : false;
}
inline bool createDirectory(const std::string& path) {
return ::CreateDirectoryA(path.data(), nullptr) ? true : false;
}
//! 应用程序典型路径辅助
//struct PathHelper {
//
//
//};
}
}
......@@ -90,7 +90,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util", "util", "{E13021FA-C
..\jlib\util\space.h = ..\jlib\util\space.h
..\jlib\util\std_util.h = ..\jlib\util\std_util.h
..\jlib\util\str_util.h = ..\jlib\util\str_util.h
..\jlib\util\version_no.h = ..\jlib\util\version_no.h
..\jlib\util\version.h = ..\jlib\util\version.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dp", "dp", "{8D9BBE8F-28BE-481B-A27F-A87526A78C67}"
......@@ -230,6 +230,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_file_op", "test_file_o
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_path_op", "test_path_op\test_path_op.vcxproj", "{65C310A4-DAA5-4D94-91B3-848F4E5F5C17}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_version", "test_version\test_version.vcxproj", "{704FF7EB-D633-4D0A-957B-01D908478D6D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
......@@ -364,6 +366,14 @@ Global
{65C310A4-DAA5-4D94-91B3-848F4E5F5C17}.Release|x64.Build.0 = Release|x64
{65C310A4-DAA5-4D94-91B3-848F4E5F5C17}.Release|x86.ActiveCfg = Release|Win32
{65C310A4-DAA5-4D94-91B3-848F4E5F5C17}.Release|x86.Build.0 = Release|Win32
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Debug|x64.ActiveCfg = Debug|x64
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Debug|x64.Build.0 = Debug|x64
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Debug|x86.ActiveCfg = Debug|Win32
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Debug|x86.Build.0 = Debug|Win32
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Release|x64.ActiveCfg = Release|x64
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Release|x64.Build.0 = Release|x64
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Release|x86.ActiveCfg = Release|Win32
{704FF7EB-D633-4D0A-957B-01D908478D6D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -406,6 +416,7 @@ Global
{42F7EE20-C9AC-49CE-9D92-479576295810} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{82EF7CB9-D551-43FC-A2A5-485C37C7895B} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{65C310A4-DAA5-4D94-91B3-848F4E5F5C17} = {0E6598D3-602D-4552-97F7-DC5AB458D553}
{704FF7EB-D633-4D0A-957B-01D908478D6D} = {ABCB8CF8-5E82-4C47-A0FC-E82DF105DF99}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8EBEA58-739C-4DED-99C0-239779F57D5D}
......
......@@ -17,7 +17,7 @@ int main()
auto name2 = integrateFileName(name);
printf("integrateFileName:\nold=%s\nnew=%s\n", name.data(), name2.data());
printf("getAppDataPathA=%s\n", getAppDataPathA().data());
//printf("getAppDataPathA=%s\n", getAppDataPathA().data());
printf("getTempFileName=%s\n", getTempFileNameA().data());
system("pause");
......
#include "../../jlib/util/version.h"
#include <stdio.h>
#include <assert.h>
using namespace jlib;
int main()
{
Version v1; printf("default ctor: %s\n", v1.toString().data());
Version v2(0, 0, 0, 1);
assert(v2.valid());
assert(v2 == Version("0.0.0.1"));
printf("v2: %s\n", v2.toString().data());
v2.toFile("v2.ini");
Version v3; v3.fromFile("v2.ini");
assert(v2 == v3);
printf("v3: %s\n", v3.toString().data());
Version v4(0, 0, 0, 2);
assert(!(v3 == v4));
assert(v3 < v4);
assert(v4 > v3);
system("pause");
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{704FF7EB-D633-4D0A-957B-01D908478D6D}</ProjectGuid>
<RootNamespace>testversion</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="test_version.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="test_version.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
0.0.0.1
\ No newline at end of file
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