|
本帖最后由 henices 于 2017-10-17 13:58 编辑 , c% Q1 ]! k0 u y' E( x# {: T
5 E% c+ w# {0 c! Phttp://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?
, @ E W+ d' w' u- l- t0 s
/ B2 `" c8 z b# D
6 y4 ]. ^/ O1 N& ^- $ y7 t. |2 G) y, W$ Z) M! L/ G
- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>
* i8 Z# ~7 l: C9 k' p9 s l - " P8 `5 r$ s7 g. B+ w0 _
- >>> import hashlib
8 f$ Z0 T; U u s1 j& u - >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()
* |, g- X. c9 P& ] l0 s - '139305d43503a41a44ebf590fd8f3fae'+ i4 T. a$ k3 _
复制代码
! g& R* t: z6 R1 J. e, n
E* Y2 t5 n' q# E/ q: l使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId
6 A- u& w3 W& H4 c
1 U& ^! W' N# N9 A% {) ]% f% H- ) `2 W5 _1 i% z$ h0 ~8 B# c
- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw() # O) s2 P2 x! S& m. Z2 |! `
- {
, F, k; |/ i2 ^% h$ d5 ` - std::vector< string > sortedList;
+ X, y' J: ?! p- m - 6 H9 }+ W: E- x
- if ( Config::isPortableVersion() ) 5 d& M$ @8 P% s" k7 a4 K; Z6 S0 {
- {
+ D+ l9 R, B) O/ `3 M3 P - // For portable version, we use relative paths / H; P3 f1 m" [0 |9 u K% b
- sortedList.reserve( dictionaryFiles.size() ); 3 B$ L$ n4 g4 j; b3 [7 r& P: F/ t
- 5 P* F2 d# Q9 p ^% q D
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); $ C. g& X! y8 x
- 2 {# W$ B9 S, R. @+ f# Z: O, d
- for( unsigned x = 0; x < dictionaryFiles.size(); ++x ) & S% }4 t$ l; D* ?/ F: b) `
- { / C, [, ^0 a- O ^: e' [- w
- string const & full( dictionaryFiles[ x ] ); 1 \- H7 C, G9 F: D
-
! w# E9 C" i( B3 X9 W7 g) v, w - QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) ); 2 u0 c7 ?- d9 A/ b
- $ ]4 T4 t" W3 m1 `0 H% x+ X
- if ( fileInfo.isAbsolute() )
, z3 [* a" B) P2 n - sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) );
7 ~8 f, A* r; `; [ - else ! V( Z) {! P/ p. \0 `; u* e
- {
$ m2 \' A6 j0 {5 ` - // Well, it's relative. We don't technically support those, but
; P6 ]: h. K2 N+ \1 _ - // what the heck
7 D0 l6 R+ s7 k+ D5 S& x5 h - sortedList.push_back( full ); : f }/ C* L) q' k; V
- }
0 T* h0 O1 @4 K9 N2 Y& }0 ] - }
- R$ V6 S0 F& F - } - p# N0 T$ j) i# C9 k; `
- else
% y( E8 x# R1 o7 e1 R- g8 ~9 c8 g - sortedList = dictionaryFiles;
9 X. G! j8 [# g -
: O) d+ t9 q) e% J - std::sort( sortedList.begin(), sortedList.end() );
" j9 N1 K) P7 ^1 Y, d }3 G - . W. \- g3 R0 E
- QCryptographicHash hash( QCryptographicHash::Md5 ); % Z. S7 o2 a. X5 p
- + q& Z W) q3 T& v2 j, f
- for( std::vector< string >::const_iterator i = sortedList.begin(); + e( y( U f9 |
- i != sortedList.end(); ++i ) + A$ W8 n' g$ z6 Q9 q& B
- hash.addData( i->c_str(), i->size() + 1 ); $ s, s$ O6 c$ ^" _2 J, r( p7 H
- 3 s' c: B! c' k4 L0 ?! S) w" `
- return hash.result().toHex().data(); 1 S# M- v1 e* H/ @
- } 6 _) t ]; V& c4 R( |+ h
复制代码
3 d1 M" ^7 e$ I' h. x5 ?* F$ H7 r& l0 W# G; f0 ~
2 @7 X" J6 Z X) g
各种来源的 ID 是随机生成的 (website/wiki/program/...); M- r! k# E3 h
; k) c5 ]5 V0 x' q( Msources.cc$ l+ \" F8 |3 A' U8 l2 X5 K
- ' z7 t3 q6 a" X y* [% q( W
- void ProgramsModel::addNewProgram()
! j, p, d' f& O- y/ Y - {
$ J/ }& E* x9 D# y) ~ - Config::Program p;
6 |- r& C0 G3 b& a! V1 j ] -
' t& e! P6 L. Y# X - p.enabled = false; 7 H& i. y t5 k' j( Y4 X6 u$ H" ]# s* c
- p.type = Config::Program::Audio; 0 x9 \- u8 X+ R! c% ~5 N
- 3 f V: q* z* d, L; @/ j
- p.id = Dictionary::generateRandomDictionaryId();
* D! @! N9 ]/ }7 q2 N& D -
1 ~& `0 Z4 r9 H# ^ {7 y6 \ - beginInsertRows( QModelIndex(), programs.size(), programs.size() );
" f- U" g. k3 i2 E+ |6 v3 g - programs.push_back( p ); - ~0 K4 p5 E4 a: R3 l
- endInsertRows(); + J6 d0 i" j$ E' A
- }
3 C6 Z+ \) Q6 W3 M7 M" J9 p
复制代码 / }+ L/ A- j' T; ~: U4 F; N) N
' Y* q" X; @' d7 _2 L. C; Y* w3 hdictionary.cc % U4 s: K) ~: J
- 7 z- {8 d" g7 E" I$ o
- QString generateRandomDictionaryId()
5 v" N0 Z/ F! J/ J; X+ h, m - { 3 f T, R* {- h& `/ @* J
- return QString(
/ O7 x9 I& d" V5 f$ n - QCryptographicHash::hash(
) T1 S5 a, ~. W0 O7 k# O) J* N" F - QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(),
4 m1 x8 O- c2 x' C, q$ m - QCryptographicHash::Md5 ).toHex() ); 8 z8 x1 o X* Y* ^& k
- }
- d% V" |3 n B# y5 r
复制代码
y3 C. h/ g2 H" D9 d) ?+ h! ` |
评分
-
5
查看全部评分
-
|