|
本帖最后由 henices 于 2017-10-17 13:58 编辑 ! s+ t3 V. c. ^1 u
' h' `( f( g# n6 s* }! s6 ]# q2 s+ Uhttp://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?7 X# \9 d: y* `
" b3 _1 E6 x' e+ v* r5 n' f7 [& J
( |; o) Q9 L7 r R3 y. c' a* q
( p5 I' {+ {, ?- [9 W% k- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>
2 h( ^" R! W" k0 U - ; w- W- ^7 G" |) o) H
- >>> import hashlib
3 }! \' E% i# U2 q; M - >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()3 N) a. h# L0 Q! d2 z; c* I6 |
- '139305d43503a41a44ebf590fd8f3fae', C! i3 g; x; [/ N8 K4 i
复制代码
7 z, u* u7 s9 ^! Q1 X1 n' s
0 c) j" v& \* M$ w; A8 V$ C使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId
- R1 S3 L: e* I. s6 ]0 _9 B, c
5 Q0 x ?) e9 k: C, z7 @- 3 v3 w+ x M0 ]
- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw()
" m, v# q* e# J( b8 r: k s - { $ ]# H: h) }1 g6 j3 M
- std::vector< string > sortedList;
; J6 m8 u* n. ?3 w7 c* ] - ' b% i( y# ~) \5 j# Y
- if ( Config::isPortableVersion() ) 7 f v3 n9 q' J }
- { $ H l$ c/ c; |3 m }- e
- // For portable version, we use relative paths
2 Y A( _) @9 h& g - sortedList.reserve( dictionaryFiles.size() ); ! e1 E) B0 I' U& Y G
- ) _" m) E. M* Z8 G( c
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); / v3 ~8 N" r# p" E5 A
-
4 ~6 ~, W- t1 s - for( unsigned x = 0; x < dictionaryFiles.size(); ++x ) 8 a" O: K* Y- t
- {
: m9 j6 I& s% o; W - string const & full( dictionaryFiles[ x ] );
5 P& e6 U, l& M+ A; F -
# X% |) _( G* s5 Q3 | - QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) );
& U) v1 f9 G7 o; Y - - L0 z9 P5 }( O N3 \3 o0 Z
- if ( fileInfo.isAbsolute() ) ! l5 e; c# r2 f2 ^7 A7 R% R5 ?
- sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) );
) \8 f* a6 I6 f ?6 h - else ) K, q* D5 m" }, i9 K; F
- { & Y3 b) s. v0 r$ b
- // Well, it's relative. We don't technically support those, but
/ N+ M7 o4 ~' m" l; R- d( g. H - // what the heck
2 p3 U i+ @( P! h" s9 u$ M; G - sortedList.push_back( full ); / q% t9 j' H- o! G" R
- } " ]; ]9 W9 Z5 ?- {
- }
( P |% [8 F" ]7 v2 a - } 9 j( ~! D6 S; {$ G& {3 i5 [3 d' [
- else
* U' w$ l. ]4 D% ]0 s - sortedList = dictionaryFiles; 3 u. [5 Q* A! n( o/ z
-
z4 a s& R- O) I/ d2 v4 H - std::sort( sortedList.begin(), sortedList.end() );
" Q6 M/ d" J9 L$ V - # W, C; X# {5 ~$ p6 w5 A
- QCryptographicHash hash( QCryptographicHash::Md5 );
4 ^" N/ r! h- L( l6 z8 G; ? - 2 W0 R! |' |' g% M# @2 u8 _4 H" u
- for( std::vector< string >::const_iterator i = sortedList.begin();
4 X( X: `! C4 p; O6 ~# q - i != sortedList.end(); ++i )
1 ]% [" d& B" D1 z5 H& b" d& h! w - hash.addData( i->c_str(), i->size() + 1 ); - N+ o, l( e: n# [3 X: v" R
-
( h- X" R; x& A$ s - return hash.result().toHex().data(); % f) j9 ]3 _7 h' n8 u1 K+ T+ K
- } : A' U9 \, ^6 r/ }5 r
复制代码
$ ^0 `6 Y/ j$ v+ [' k$ z
# @6 G' F5 {& `. m3 S! ~9 C# w% c
各种来源的 ID 是随机生成的 (website/wiki/program/...)( ]) L; n& m" D: a* c
- f, }& w3 e, g6 B! o! R* @sources.cc
# T' W7 `9 I* b- + X% ]4 X$ N& r R! y) m
- void ProgramsModel::addNewProgram() 0 Z8 B2 ?: `& w9 x0 o
- { 5 f. Q; d4 o+ ^) O0 ^4 `
- Config::Program p;
0 o N+ |+ \# I -
. _% X0 n8 P# a/ Y. @3 P$ k! _ - p.enabled = false;
# v: R/ `' |: k' m5 R& U* Z$ r - p.type = Config::Program::Audio; 0 _( C' u. i! i" ^4 Q
- B7 V G1 ?& d* g* `+ ^- B7 q
- p.id = Dictionary::generateRandomDictionaryId();
. l# S8 {" \5 A9 ` - , [1 U1 L$ X9 r7 O1 B3 r
- beginInsertRows( QModelIndex(), programs.size(), programs.size() );
9 E% a4 \& L. O" }3 Y - programs.push_back( p );
0 z( f" l8 Q- m# g: b* w - endInsertRows();
' ~/ _+ Z1 E3 N1 g- [& {3 H - } # c" n" C, U4 ?" u! M
复制代码 : C) Z4 f7 _+ x
0 R8 z5 {' S; L( H9 `
dictionary.cc
* O# l4 L( Z$ x! @7 P: R6 ?
* B) e3 u4 _, X0 A1 _5 _- QString generateRandomDictionaryId()
G; z/ P0 Y- U3 u' u - { 4 ^5 K5 A2 m, f
- return QString(
N8 }: a; I" h0 c, S1 g3 r2 \ - QCryptographicHash::hash(
" r l% d3 i8 h. _9 q - QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(), 8 W( e( x5 r$ u! b( ^8 c8 @
- QCryptographicHash::Md5 ).toHex() ); 3 w" s1 C/ k. `2 f
- }
. B. s2 b! @ v: ?
复制代码
' t& d4 K) f6 d2 D( x/ ~) q5 o% O |
评分
-
5
查看全部评分
-
|