Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
d7094cf5
Commit
d7094cf5
authored
Aug 09, 2021
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6afaf1d4
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
198 additions
and
3 deletions
+198
-3
QtDebug.h
jlib/qt/QtDebug.h
+12
-0
QRunGuard.cpp
jlib/qt/Util/QRunGuard.cpp
+75
-0
QRunGuard.h
jlib/qt/Util/QRunGuard.h
+34
-0
monitor.h
jlib/qt/monitor.h
+21
-0
qt.vcxproj
jlib/qt/qt.vcxproj
+2
-0
qt.vcxproj.filters
jlib/qt/qt.vcxproj.filters
+9
-0
space.h
jlib/util/space.h
+1
-1
baseboard.cpp
jlib/win32/info/baseboard.cpp
+2
-2
diskdrive.cpp
jlib/win32/info/diskdrive.cpp
+38
-0
diskdrive.h
jlib/win32/info/diskdrive.h
+1
-0
path_op.h
jlib/win32/path_op.h
+3
-0
No files found.
jlib/qt/QtDebug.h
View file @
d7094cf5
#pragma once
#include <QDebug>
#include <QDateTime>
#ifdef _WIN32
#include <Windows.h>
#endif //_WIN32
...
...
@@ -19,6 +21,16 @@
#define MYQWARN_NOQUOTE qWarning().noquote() << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQCRITICAL_NOQUOTE qCritical().noquote() << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQDEBUG2 qDebug() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQINFO2 qInfo() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQWARN2 qWarning() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQCRITICAL2 qCritical() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQDEBUG2_NOQUOTE qDebug().noquote() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQINFO2_NOQUOTE qInfo().noquote() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQWARN2_NOQUOTE qWarning().noquote() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
#define MYQCRITICAL2_NOQUOTE qCritical().noquote() << QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss") << JLIBQT_QDEBUG_FILE_LINE_STREAM
//! 弹窗报告行号开关
// #define JLIBQT_SHOW_LINE 0
//! 当行号大于下方定义的值时,弹窗报告行号,否则忽略。可在多个cpp文件分别定义不同的值。
...
...
jlib/qt/Util/QRunGuard.cpp
0 → 100644
View file @
d7094cf5
#include "QRunGuard.h"
#include <QCryptographicHash>
static
QString
generateKeyHash
(
const
QString
&
key
,
const
QString
&
salt
)
{
QByteArray
data
;
data
.
append
(
key
.
toUtf8
());
data
.
append
(
salt
.
toUtf8
());
data
=
QCryptographicHash
::
hash
(
data
,
QCryptographicHash
::
Sha1
).
toHex
();
return
data
;
}
JLIBQT_NAMESPACE_BEGIN
RunGuard
::
RunGuard
(
const
QString
&
key
)
:
key
(
key
)
,
memLockKey
(
generateKeyHash
(
key
,
"_memLockKey"
))
,
sharedmemKey
(
generateKeyHash
(
key
,
"_sharedmemKey"
))
,
sharedMem
(
sharedmemKey
)
,
memLock
(
memLockKey
,
1
)
{
memLock
.
acquire
();
{
QSharedMemory
fix
(
sharedmemKey
);
// Fix for *nix: http://habrahabr.ru/post/173281/
fix
.
attach
();
}
memLock
.
release
();
}
RunGuard
::~
RunGuard
()
{
release
();
}
bool
RunGuard
::
isAnotherRunning
()
{
if
(
sharedMem
.
isAttached
())
return
false
;
memLock
.
acquire
();
const
bool
isRunning
=
sharedMem
.
attach
();
if
(
isRunning
)
sharedMem
.
detach
();
memLock
.
release
();
return
isRunning
;
}
bool
RunGuard
::
tryToRun
()
{
if
(
isAnotherRunning
())
// Extra check
return
false
;
memLock
.
acquire
();
const
bool
result
=
sharedMem
.
create
(
sizeof
(
quint64
));
memLock
.
release
();
if
(
!
result
)
{
release
();
return
false
;
}
return
true
;
}
void
RunGuard
::
release
()
{
memLock
.
acquire
();
if
(
sharedMem
.
isAttached
())
sharedMem
.
detach
();
memLock
.
release
();
}
JLIBQT_NAMESPACE_END
jlib/qt/Util/QRunGuard.h
0 → 100644
View file @
d7094cf5
#pragma once
#include <QObject>
#include <QString>
#include <QSharedMemory>
#include <QSystemSemaphore>
#include "../qt_global.h"
JLIBQT_NAMESPACE_BEGIN
class
RunGuard
{
public
:
RunGuard
(
const
QString
&
key
);
~
RunGuard
();
bool
isAnotherRunning
();
bool
tryToRun
();
void
release
();
private
:
const
QString
key
;
const
QString
memLockKey
;
const
QString
sharedmemKey
;
QSharedMemory
sharedMem
;
QSystemSemaphore
memLock
;
Q_DISABLE_COPY
(
RunGuard
)
};
JLIBQT_NAMESPACE_END
jlib/qt/monitor.h
View file @
d7094cf5
...
...
@@ -280,6 +280,27 @@ static void disableMonitor(const MonitorInfo& m) {
commitChange
();
}
static
void
enableMonitor
(
const
wchar_t
*
deviceName
,
int
w
,
int
h
)
{
DEVMODEW
dm
=
{
0
};
dm
.
dmSize
=
sizeof
(
dm
);
dm
.
dmFields
=
DM_POSITION
|
DM_PELSWIDTH
|
DM_PELSHEIGHT
;
dm
.
dmPelsWidth
=
w
;
dm
.
dmPelsHeight
=
h
;
DWORD
dwFlags
=
CDS_UPDATEREGISTRY
|
CDS_GLOBAL
|
CDS_NORESET
;
auto
ret
=
ChangeDisplaySettingsExW
(
deviceName
,
&
dm
,
nullptr
,
dwFlags
,
nullptr
);
MYQDEBUG
<<
"enableMonitor ChangeDisplaySettingsExW returns:"
<<
(
ret
==
ERROR_SUCCESS
);
commitChange
();
}
static
void
enableMonitor
(
const
MonitorInfo
&
m
,
const
MonitorInfo
::
Resolution
&
res
)
{
enableMonitor
(
m
.
deviceName
.
toStdWString
().
data
(),
res
.
w
,
res
.
h
);
}
static
void
setMainMonitor
(
const
MonitorInfo
&
newMain
,
const
MonitorInfo
&
oldMain
)
{
auto
moveOld
=
[](
const
MonitorInfo
&
newMain
,
const
MonitorInfo
&
oldMain
)
{
DEVMODEW
dm
=
{
0
};
...
...
jlib/qt/qt.vcxproj
View file @
d7094cf5
...
...
@@ -95,6 +95,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"qt.cpp"
/>
<ClCompile
Include=
"Util\QRunGuard.cpp"
/>
<ClCompile
Include=
"View\BaseScrollView.cpp"
/>
<ClCompile
Include=
"View\BgColorBtn.cpp"
/>
<ClCompile
Include=
"View\CheckBtn.cpp"
/>
...
...
@@ -107,6 +108,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"Util\QRunGuard.h"
/>
<QtMoc
Include=
"View\ProgressDialog.h"
/>
<QtMoc
Include=
"View\TextMenu.h"
/>
<QtMoc
Include=
"View\PageView.h"
/>
...
...
jlib/qt/qt.vcxproj.filters
View file @
d7094cf5
...
...
@@ -33,6 +33,9 @@
<Extensions>
ui
</Extensions>
<ParseFiles>
true
</ParseFiles>
</Filter>
<Filter
Include=
"Util"
>
<UniqueIdentifier>
{80767180-97c3-403d-8d10-8e7069736c61}
</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"qt.cpp"
>
...
...
@@ -65,6 +68,9 @@
<ClCompile
Include=
"View\ProgressDialog.cpp"
>
<Filter>
View
</Filter>
</ClCompile>
<ClCompile
Include=
"Util\QRunGuard.cpp"
>
<Filter>
Util
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"qt.h"
>
...
...
@@ -97,6 +103,9 @@
<ClInclude
Include=
"resource.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"Util\QRunGuard.h"
>
<Filter>
Util
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"qt_global.h"
>
...
...
jlib/util/space.h
View file @
d7094cf5
...
...
@@ -25,7 +25,7 @@ static inline std::string human_readable_byte_count(uintmax_t bytes, PositionalN
auto
pre
=
std
::
string
(
"KMGTPEZYBND"
).
at
(
exp
-
1
)
+
std
::
string
(
po
==
PositionalNotation
::
Binary
?
"i"
:
""
);
auto
var
=
bytes
/
std
::
pow
(
unit
,
exp
);
char
buf
[
64
]
=
{
0
};
snprintf
(
buf
,
sizeof
(
buf
),
"%
g
%sB"
,
var
,
pre
.
data
());
snprintf
(
buf
,
sizeof
(
buf
),
"%
.2f
%sB"
,
var
,
pre
.
data
());
return
buf
;
}
...
...
jlib/win32/info/baseboard.cpp
View file @
d7094cf5
...
...
@@ -41,7 +41,7 @@ std::string serial()
auto
serial
=
result
[
0
][
L"SerialNumber"
];
return
utf16_to_mbcs
(
serial
);
}
return
std
::
string
();
return
std
::
string
(
"System Serial Number"
);
}
std
::
string
bios_serial
()
...
...
@@ -50,7 +50,7 @@ std::string bios_serial()
if
(
wmi
::
WmiBase
::
simpleSelect
({
L"SerialNumber"
},
L"Win32_BIOS"
,
L""
,
result
)
&&
result
.
size
()
==
1
)
{
auto
serial
=
result
[
0
][
L"SerialNumber"
];
}
return
std
::
string
();
return
std
::
string
(
"System Serial Number"
);
}
...
...
jlib/win32/info/diskdrive.cpp
View file @
d7094cf5
...
...
@@ -51,6 +51,44 @@ std::string bootable_disk_serial()
return
{};
}
std
::
string
bootable_disk_serial_old
()
{
std
::
vector
<
std
::
wstring
>
values
,
errors
;
auto
output
=
[
&
values
](
const
std
::
wstring
&
key
,
const
std
::
wstring
&
value
)
{
values
.
push_back
(
value
);
};
auto
error
=
[
&
errors
](
HRESULT
hr
,
const
std
::
wstring
&
msg
)
{
errors
.
push_back
(
msg
);
};
wmi
::
WmiBase
wmi
(
L"ROOT
\\
CIMV2"
,
output
,
error
);
if
(
!
wmi
.
prepare
())
{
return
{};
}
auto
sz
=
values
.
size
();
// possible value:
// Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk4\Partition4
if
(
wmi
.
execute
(
L"Select Name from Win32_OperatingSystem"
)
&&
values
.
size
()
==
sz
+
1
)
{
auto
index
=
values
.
back
();
values
.
pop_back
();
auto
pos
=
index
.
find
(
L"Harddisk"
);
if
(
pos
!=
index
.
npos
)
{
auto
rpos
=
index
.
find
(
L"
\\
Partition"
,
pos
);
if
(
rpos
!=
index
.
npos
&&
rpos
-
pos
>
strlen
(
"Harddisk"
))
{
auto
n
=
index
.
substr
(
pos
+
strlen
(
"Harddisk"
),
rpos
-
pos
-
strlen
(
"Harddisk"
));
if
(
wmi
.
execute
(
L"SELECT SerialNumber FROM Win32_DiskDrive WHERE Index = "
+
n
)
&&
!
values
.
empty
())
{
//results[queryType] = values.back(); values.pop_back();
//continue;
return
utf16_to_mbcs
(
values
.
back
());
}
}
}
}
return
{};
}
}
}
}
...
...
jlib/win32/info/diskdrive.h
View file @
d7094cf5
...
...
@@ -22,6 +22,7 @@ struct DiskDrive {
JINFO_API
std
::
vector
<
DiskDrive
>
disk_drives
();
JINFO_API
std
::
string
bootable_disk_serial
();
JINFO_API
std
::
string
bootable_disk_serial_old
();
}
}
...
...
jlib/win32/path_op.h
View file @
d7094cf5
...
...
@@ -61,6 +61,9 @@ inline std::string getAppDataPathA() { return getSpecialFolderA(CSIDL_APPDATA);
inline
std
::
wstring
getTempPath
()
{
wchar_t
path
[
MAX_PATH
]
=
{
0
};
::
GetTempPathW
(
MAX_PATH
,
path
);
return
path
;
}
inline
std
::
string
getTempPathA
()
{
char
path
[
MAX_PATH
]
=
{
0
};
::
GetTempPathA
(
MAX_PATH
,
path
);
return
path
;
}
inline
std
::
wstring
getMyDocumentsPath
()
{
return
getSpecialFolder
(
CSIDL_MYDOCUMENTS
);
}
inline
std
::
string
getMyDocumentsPathA
()
{
return
getSpecialFolderA
(
CSIDL_MYDOCUMENTS
);
}
inline
std
::
wstring
getTempFileName
(
const
std
::
wstring
&
folder
,
const
std
::
wstring
&
pre
)
{
wchar_t
path
[
MAX_PATH
]
=
{
0
};
UINT
ret
=
::
GetTempFileNameW
(
folder
.
c_str
(),
pre
.
c_str
(),
0
,
path
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment