|
本帖最后由 henices 于 2017-10-17 13:58 编辑 ) A9 A# o, P% d" G6 d" p" M
, T+ K3 A( k0 n+ b9 o
http://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?$ A$ E4 p6 o0 I7 }' t8 t# U
. ^( Z" u# L+ k$ r1 Q
% Q& C, k- U+ B6 {
- 0 F1 k8 |6 p+ J1 J( ]
- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>1 E0 b1 y* U6 f
- % g$ j5 {- B `+ d
- >>> import hashlib
1 X( }7 T4 q9 s' x - >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()
4 L- H! ] x" r3 P6 s' b# D - '139305d43503a41a44ebf590fd8f3fae'9 _$ y* O( w! r6 @! T
复制代码
1 S$ m" J' y' a) g+ \1 ?" z
& Z8 J7 w% C- }使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId0 E, k5 `, B' g) Z0 x
. f# x! J! j5 B- w
- 5 ?, i: \1 Z7 c7 ~
- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw()
7 c: m3 p/ Z X! {: V - { 9 T4 ]- g X" V, V8 D0 K/ G
- std::vector< string > sortedList; 2 ~& ?: X5 B, r$ b, J
- . O, O/ w3 b; S
- if ( Config::isPortableVersion() )
- _! X. C. b W5 K1 C0 r - {
% \0 Q" x0 I0 e/ S# v9 p; { - // For portable version, we use relative paths
5 k- V) v {1 o5 H: m% I - sortedList.reserve( dictionaryFiles.size() );
9 k" W& k. \) m' ^2 J' m) ^ [' [, g: j - / N* O0 U6 ?) D( |4 o1 }4 o
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); 6 E9 }: k' [9 o2 w9 ?, I# l
-
; R8 @4 p5 s" ]6 D, k - for( unsigned x = 0; x < dictionaryFiles.size(); ++x )
; k* O! h" V! u: F; h, | - {
; N, E+ \) r0 c/ x4 H4 [ - string const & full( dictionaryFiles[ x ] );
6 P4 B3 p. S( O3 D, Q, O -
4 t- w: }* B# t" a- d - QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) ); # @5 t( ^% m. L- _. b7 c9 J9 r3 e$ D
-
- @" `$ |$ M, ~1 O4 j - if ( fileInfo.isAbsolute() ) ( C* u# E% {( D+ M% D
- sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) ); , C* W( ^9 j- n+ ^& b* I8 P1 R) h) z8 ~
- else
3 [7 I. `$ n( V3 ^' W - { % _& X5 ~& f3 A! y0 s1 A/ g0 A' b
- // Well, it's relative. We don't technically support those, but ) W) L; t# J; n) ^
- // what the heck
8 S' U. S0 l9 m* ^; a8 |! W - sortedList.push_back( full );
* _/ D4 Q( ~3 r5 l2 f" \% r - } 8 B# v, o5 Z0 v% i
- }
6 y/ F/ b. M- o/ F: T0 [1 P# o, S - } , J9 _7 C/ l& C$ |5 v! G+ J w" A
- else
3 x& o3 D! G( v - sortedList = dictionaryFiles; % D. L. j4 Q+ \: j; f- b7 I* y, B
-
- P8 U' _, B, T- i6 F6 Y* m - std::sort( sortedList.begin(), sortedList.end() );
; ]% g8 W( l+ G -
9 ?5 ^' K. n6 n& `/ i& l - QCryptographicHash hash( QCryptographicHash::Md5 ); & D7 ?0 C# ]9 Y+ K' Q) ]
- 3 T* ^/ w6 U3 X2 j: F- C' e: [. y
- for( std::vector< string >::const_iterator i = sortedList.begin(); ! @6 e' `7 Y0 t7 Q+ E( [
- i != sortedList.end(); ++i )
8 |. ^$ C+ M5 Z6 ? V$ ^ - hash.addData( i->c_str(), i->size() + 1 );
, C; v: r9 t( w! j, x' l -
! ]. f3 T& ^4 l/ r1 y$ U" h - return hash.result().toHex().data(); 1 l& R j! l4 F. n3 |) w- v6 f. ?
- } ; _) H1 ?5 S4 o, D4 I
复制代码 / ?) S2 R! R3 E# Q# b. v3 U
( R5 n% j l; i2 `: [; l$ Y# A* i/ E& H5 J& `" s
各种来源的 ID 是随机生成的 (website/wiki/program/...)
# C' R. C; l H; D
& N4 C/ S! `' [4 O/ K, |sources.cc- Z) U* ~0 B0 ]2 r8 X' P3 N7 \4 T) c
- * d& B4 ?6 J" A/ @# P
- void ProgramsModel::addNewProgram() ' ~, W/ J. k! ], s+ ~
- { $ u) f9 [( i4 r0 l
- Config::Program p; : F" @. s6 {, y, i, @
- 6 K$ J: B6 r/ v% j; C
- p.enabled = false; 1 W1 j' L1 g0 L' D0 w
- p.type = Config::Program::Audio;
3 u. |, t: `" ^/ b: \# ? -
5 S# f A& _/ a8 _5 r; B/ _# I - p.id = Dictionary::generateRandomDictionaryId();
; C0 j, \$ ]* v; X9 G2 b& o -
+ C9 F9 H0 y4 G5 c5 u2 Q - beginInsertRows( QModelIndex(), programs.size(), programs.size() );
J; p- n8 {# \ - programs.push_back( p );
+ ]3 A% ^$ |$ F. B" F - endInsertRows(); 3 O6 [. a; g' ~: T4 x# x
- }
4 i6 O. _: q b: U; \( }
复制代码
; f$ }& g! k1 V t& i2 }, a: a; {: F7 e! W }- \" |. d
dictionary.cc
3 y5 ? ]$ r: F9 I
' ]8 e( I+ F& U3 J7 }- [& ~- QString generateRandomDictionaryId()
8 C3 O- ?! B% w# m3 E* k0 P, x+ r - {
, z8 R" H) f5 |, L0 w9 K# J0 C, j - return QString( 9 P: Q9 S C& N. Y5 i
- QCryptographicHash::hash( 4 E$ W- q7 Q; v+ N J
- QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(),
3 k) f+ c; I: B4 I" q- ] - QCryptographicHash::Md5 ).toHex() ); / m5 m4 M: J7 E2 C1 `
- } " ] C4 l/ q3 }1 n- J; L& J
复制代码 , s" E- D0 Q9 e; N; X
|
评分
-
5
查看全部评分
-
|