4 # Praat script handling configuration page
6 # SpeakGoodChinese: Config.praat loads the code needed for the
7 # settings and the Settings page of SpeakGoodChinese.
9 # Copyright (C) 2007-2010 R.J.J.H. van Son
10 # The SpeakGoodChinese team are:
11 # Guangqin Chen, Zhonyan Chen, Stefan de Koning, Eveline van Hagen,
12 # Rob van Son, Dennis Vierkant, David Weenink
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 ###############################################################
31 # Button Drawing Routines
33 ###############################################################
35 procedure DrawCredits .color$ .x .y .size
38 call adjustFontSizeOnHeight 24 '.lineheight'
39 .currentFontSize = adjustFontSizeOnHeight.newFontSize
40 demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
42 demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 i
45 call set_font_size 'defaultFontSize'
48 procedure DrawDeleteList .color$ .x .y .size
56 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
59 .maxWidth = (.rightX - .leftX)
60 .currentFontSize = defaultFontSize
61 call adjustFontSizeOnWidth '.currentFontSize' '.maxWidth' '.displayWordList$'
62 .currentFontSize = adjustFontSizeOnWidth.newFontSize
63 if adjustFontSizeOnWidth.diff > 0
64 .rightX += adjustFontSizeOnWidth.diff/2
65 .leftX -= adjustFontSizeOnWidth.diff/2
67 call set_font_size '.currentFontSize'
68 demo Paint rectangle... White '.leftX' '.rightX' '.botY' '.topY'
70 demo Text... '.x' Centre '.botY' Bottom '.displayWordList$'
73 call set_font_size 'defaultFontSize'
76 procedure DrawLogging .color$ .x .y .size
80 .color$ = "{0.5,0.5,1}"
84 demo Paint circle... '.color$' '.x' '.y' '.size'
87 ###############################################################
89 # Obligatory button Drawing Routines
91 # These MUST be defined
93 ###############################################################
95 procedure DrawReturn .color$ .x .y .size
96 call DrawConfig '.color$' '.x' '.y' '.size'
99 # Set the correct button states after redrawing the window
100 procedure setConfigButtons
101 # Handle logging buttons with forced button draw
102 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
103 call Draw_button 'config$' +!Logging 'config.logPerformance'
107 ###############################################################
109 # Button Processing Routines
111 ###############################################################
113 procedure processConfigShuffleLists .clickX .clickY .pressed$
115 .label$ = "ShuffleLists"
116 config.shuffleLists = not config.shuffleLists
117 .displayButton = 2*config.shuffleLists
118 call Draw_button '.table$' '.label$' '.displayButton'
121 procedure processConfigUseSoundExample .clickX .clickY .pressed$
123 .label$ = "UseSoundExample"
124 config.useSoundExample = not config.useSoundExample
125 .displayButton = 2*config.useSoundExample
126 call Draw_button '.table$' '.label$' '.displayButton'
129 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
131 .label$ = "Synthesis_'.tts$'"
132 if speakCommandFile$ <> "" and fileReadable(speakCommandFile$)
133 if config.synthesis$ = ""
134 config.synthesis$ = .tts$
137 config.synthesis$ = ""
141 config.synthesis$ = "_DISABLED_"
144 call Draw_button '.table$' '.label$' '.displayButton'
147 procedure processConfigStrict .clickX .clickY .pressed$
150 config.strict = not config.strict
158 call Draw_button '.table$' '.label$' '.displayButton'
161 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
163 .label$ = "DisplayPinyin"
164 config.displayPinyin = not config.displayPinyin
165 .displayButton = 2*config.displayPinyin
166 call Draw_button '.table$' '.label$' '.displayButton'
169 procedure processConfigDisplayChar .clickX .clickY .pressed$
171 .label$ = "DisplayChar"
172 config.displayChar = not config.displayChar
173 .displayButton = 2*config.displayChar
174 call Draw_button 'table$' '.label$' '.displayButton'
177 procedure processConfigDisplayTrans .clickX .clickY .pressed$
179 .label$ = "DisplayTrans"
180 config.displayTrans = not config.displayTrans
181 .displayButton = 2*config.displayTrans
182 call Draw_button 'table$' '.label$' '.displayButton'
185 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
187 .label$ = "DisplayNumbers"
188 config.displayNumbers = not config.displayNumbers
189 .displayButton = 2*config.displayNumbers
190 call Draw_button 'table$' '.label$' '.displayButton'
193 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
195 .label$ = "Language_'.language$'"
196 call processLanguageCodes '.table$' '.label$'
199 procedure processConfigShowBackground .clickX .clickY .pressed$
201 .label$ = "ShowBackground"
202 config.showBackground = not config.showBackground
203 .displayButton = 2*config.showBackground
204 call Draw_button 'table$' '.label$' '.displayButton'
207 procedure processConfigInput .input$ .clickX .clickY .pressed$
209 .label$ = "Input_'.input$'"
210 call Draw_button '.table$' Input_'config.input$' 0
211 config.input$ = .input$
212 call Draw_button '.table$' Input_'config.input$' 2
215 procedure processConfigRegister .register .clickX .clickY .pressed$
217 .label$ = "Register_'.register'"
218 call setRegisterFromLabel '.table$' '.label$'
221 procedure setRegisterFromLabel .table$ .label$
222 call Draw_button '.table$' Register_'config.register' 0
223 call Draw_button '.table$' '.label$' 2
224 # Someone might have to use more than 3 chars for the config.register code
225 .numChars = length(.label$) - length("Register_")
226 .registerText$ = right$(.label$, .numChars)
227 config.register = '.registerText$'
230 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
232 .label$ = "DeleteWordlist"
234 # Do not process undeletable word lists, only those stored in the
235 # preferencesDirectory$ can be deleted
236 if fileReadable("'preferencesDirectory$'/sgc2/wordlists/'wordlistName$'")
237 call findLabel '.table$' !'.label$'
239 select Table '.table$'
240 .alertText$ = Get value... 'findLabel.row' Text
241 .confirmKey$ = Get value... 'findLabel.row' Key
242 .popupText$ = Get value... 'findLabel.row' Helptext
244 exit Cannot find delete directive: '.table$' !'.label$'
246 call write_text_popup 'defaultFont$' 14 '.popupText$'
247 call Draw_button '.table$' '.label$' 2
248 alertText$ = .alertText$
249 call Draw_button '.table$' '.label$' 3
252 # Wait for confirmation
254 if demoInput(.confirmKey$)
255 .deleteWordListDir$ = wordlistName$
256 call load_word_list "'localWordlistDir$'" 1
257 call removeWordlist '.deleteWordListDir$'
259 call Draw_button '.table$' '.label$' 0
260 call Draw_config_page
264 wordlistTag$ = "Wordlist name"
265 procedure processConfigInstallWordlist .clickX .clickY .pressed$
267 .label$ = "InstallWordlist"
268 call Draw_button '.table$' '.label$' 1
270 # Do not use the automatic sgc list option, ask for a wordlist NAME
272 call findLabel '.table$' '.label$'
274 select Table '.table$'
275 .openDialogue$ = Get value... '.row' Helptext
276 call convert_praat_to_utf8 '.openDialogue$'
277 .openDialogue$ = convert_praat_to_utf8.text$
278 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
279 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
280 beginPause(.openDialogue$)
281 sentence (wordlistTag$, "")
282 clicked = endPause ("Cancel", "Open", 2)
285 .wordlist_Name$ = '.wordlistButton$'$
287 call install_wordlists_by_name '.wordlist_Name$'
289 call sgc2wordlist 'homeDirectory$'
290 call sgc2wordlist 'homeDirectory$'/Downloads
291 call sgc2wordlist 'homeDirectory$'/Documents
292 call sgc2wordlist 'homeDirectory$'/My Documents
293 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
294 call sgc2wordlist 'homeDirectory$'/Desktop
295 call sgc2wordlist 'preferencesDirectory$'/sgc2
297 call load_word_list "'localWordlistDir$'" 0
298 call Draw_button '.table$' '.label$' 0
299 call Draw_config_page
302 procedure processConfigOpenWordlist .clickX .clickY .pressed$
304 .label$ = "OpenWordlist"
305 call Draw_button '.table$' '.label$' 1
308 call findLabel '.table$' '.label$'
310 select Table '.table$'
311 .openDialogue$ = Get value... '.row' Helptext
312 call convert_praat_to_utf8 '.openDialogue$'
313 .openDialogue$ = convert_praat_to_utf8.text$
315 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
316 call install_wordlists_by_name '.wordlist_Name$'
317 call load_word_list "'localWordlistDir$'" 0
318 call Draw_button '.table$' '.label$' 0
319 call Draw_config_page
322 ###############################################################
324 # Obligatory button Processing Routines
326 # These MUST be defined
328 ###############################################################
330 procedure processConfigReturn .clickX .clickY .pressed$
333 call Draw_button '.table$' '.label$' 1
334 call write_preferences ""
337 procedure processConfigRefresh .clickX .clickY .pressed$
340 call Draw_config_page
343 procedure processConfigCredits .clickX .clickY .pressed$
346 call Draw_button '.table$' '.label$' 1
347 call write_text_table Credits_'config.language$'
349 call Draw_button '.table$' '.label$' 0
351 call Draw_config_page
354 procedure processConfigHelp .clickX .clickY .pressed$
357 call help_loop '.table$' Draw_config_page
360 ###############################################################
362 # Miscelaneous supporting code
364 ###############################################################
365 procedure install_wordlists_by_name .wordlist_Name$
366 if .wordlist_Name$ <> ""
367 printline '.wordlist_Name$'
368 if index(.wordlist_Name$, "/")
369 .sourceDir$ = left$(.wordlist_Name$, rindex(.wordlist_Name$, "/") -1)
370 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex(.wordlist_Name$, "/"))
371 call readWordlist "'.sourceDir$'" '.file$'
374 if index(.wordlist_Name$, ".")
377 .extension1$ = ".sgc"
378 .extension2$ = ".Table"
379 .extension3$ = ".txt"
381 for .e from .start to 4
382 .currentExtension$ = .extension'.e'$
383 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
384 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
385 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
386 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
387 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
388 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
389 call readWordlist "'preferencesDirectory$'/sgc2" '.wordlist_Name$''.currentExtension$'
395 # Word lists: It is a VERY good idea to make sure that word-lists
397 procedure load_word_list .localdir$ .relnumber
398 # Remove old word list
400 select Table 'wordlist$'
402 call wipeArea 'wipeWordlistArea$'
406 # Create Table that will recieve the wordlists and directories
407 Create Table with column names... AllWordLists 0 Name Directory
408 .currentWordlistRow = 0
410 # Start with the word lists in the distribution, unless the local directory exists!
411 if not fileReadable(.localdir$)
412 call CreateCreateWordlists
413 select Table CreateWordlists
414 .numLists = Get number of rows
416 select Table CreateWordlists
417 .currentName$ = Get value... '.i' Name
418 .currentDirectory$ = "*call Create'.currentName$'"
419 select Table AllWordLists
421 .currentWordlistRow = Get number of rows
422 Set string value... '.currentWordlistRow' Name '.currentName$'
423 .currentDirectory$ = "*call Create'.currentName$'"
424 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
426 select Table CreateWordlists
430 # First the global word lists
431 if fileReadable(globalwordlists$)
432 Create Strings as directory list... WordList 'globalwordlists$'
433 .numLists = Get number of strings
435 select Strings WordList
436 .currentName$ = Get string... '.i'
437 select Table AllWordLists
439 .currentWordlistRow = Get number of rows
440 Set string value... '.currentWordlistRow' Name '.currentName$'
441 .currentDirectory$ = globalwordlists$+"/"+.currentName$
442 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
444 select Strings WordList
448 # Now the preferences word lists
449 if fileReadable(sgc2wordlists$)
450 Create Strings as directory list... WordList 'sgc2wordlists$'
451 .numLists = Get number of strings
453 select Strings WordList
454 .currentName$ = Get string... '.i'
455 select Table AllWordLists
457 .currentWordlistRow = Get number of rows
458 Set string value... '.currentWordlistRow' Name '.currentName$'
459 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
460 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
462 select Strings WordList
466 # Finally, the local word lists
467 if fileReadable(.localdir$)
468 Create Strings as directory list... WordList '.localdir$'
469 .numLists = Get number of strings
471 select Strings WordList
472 .currentName$ = Get string... '.i'
473 select Table AllWordLists
475 .currentWordlistRow = Get number of rows
476 Set string value... '.currentWordlistRow' Name '.currentName$'
477 .currentDirectory$ = .localdir$+"/"+.currentName$
478 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
480 select Strings WordList
484 # Get the position of the current word list
485 select Table AllWordLists
487 .numLists = Get number of rows
488 if wordlistName$ <> ""
489 select Table AllWordLists
490 .currentNumber = Search column... Name 'wordlistName$'
492 wordlistNum = .currentNumber + .relnumber
493 if wordlistNum > .numLists
495 elsif wordlistNum < 1
496 wordlistNum = .numLists
498 select Table AllWordLists
499 wordlistName$ = Get value... 'wordlistNum' Name
500 .dirWordlistName$ = Get value... 'wordlistNum' Directory
501 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
503 # Read in full tables
504 if fileReadable("'.dirString$'/wordlist.Table")
505 Read from file... '.dirString$'/wordlist.Table
506 Rename... 'wordlistName$'
507 # Praat wil change the name if it feels like it
508 wordlist$ = selected$("Table")
509 # Handle (legacy) simple word lists
510 elsif fileReadable("'.dirString$'/wordlist.txt")
511 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
512 wordlist$ = selected$("Table")
513 Read Strings from raw text file... '.dirString$'/wordlist.txt
514 Rename... RawWordList
515 .numWordStrings = Get number of strings
516 for .i to .numWordStrings
517 select Strings RawWordList
518 .currentLine$ = Get string... '.i'
519 .currentPinyin$ = extractWord$(.currentLine$, "")
520 if length(.currentLine$) > length(.currentPinyin$)+1
521 .currentFile$ = right$(.currentLine$, length(.currentPinyin$)+1)
522 elsif fileReadable("'.dirString$'/'.currentPinyin$'.spx")
523 .currentFile$ = .currentPinyin$+".spx"
524 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
525 .currentFile$ = .currentPinyin$+".flac"
526 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
527 .currentFile$ = .currentPinyin$+".wav"
528 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
529 .currentFile$ = .currentPinyin$+".mp3"
533 select Table 'wordlist$'
535 Set string value... '.i' Pinyin '.currentPinyin$'
536 Set string value... '.i' Sound '.currentFile$'
538 select Strings RawWordList
541 select Table 'wordlist$'
542 elsif fileReadable(.dirString$)
543 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
544 wordlist$ = selected$("Table")
545 Create Strings as file list... RawWordList '.dirString$'/*
546 .numWordStrings = Get number of strings
548 for .j to .numWordStrings
549 select Strings RawWordList
550 .currentLine$ = Get string... '.j'
551 .currentFile$ = extractWord$(.currentLine$, "")
552 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
553 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
554 select Table 'wordlist$'
557 Set string value... '.i' Pinyin '.currentPinyin$'
558 Set string value... '.i' Sound '.currentFile$'
561 select Strings RawWordList
564 select Table 'wordlist$'
565 elsif startsWith(.dirString$, "*call ")
566 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
568 wordlist$ = selected$("Table")
571 # Can this wordlist be deleted?
572 if fileReadable("'preferencesDirectory$'/sgc2/wordlists/'wordlistName$'")
573 config.deleteWordlist = 0
575 config.deleteWordlist = -1
578 # Add a Character and Translation column if missing
579 select Table 'wordlist$'
580 numberOfWords = Get number of rows
581 .characterColumn = Get column index... Character
582 if not .characterColumn
583 Append column... Character
584 for .i to numberOfWords
585 Set string value... '.i' Character -
588 .translationColumn = Get column index... Translation
589 if not .translationColumn
590 Append column... Translation
591 for .i to numberOfWords
592 Set string value... '.i' Translation -
596 # Remove all rows without Pinyin
597 .numRows = Get number of rows
599 .rowNum = .numRows - i + 1
600 .pinyinValue$ = Get value... '.rowNum' Pinyin
601 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
602 Remove row... '.rowNum'
605 numberOfWords = Get number of rows
607 # Shuffle words if requested
608 if config.shuffleLists
613 select Table AllWordLists
616 # There were no Word Lists
619 wordlistName$ = "No Word Lists available"
621 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
622 wordlist$ = selected$("Table")
626 Set string value... '.i' Pinyin ni3hao3
627 Set string value... '.i' Character -
628 Set string value... '.i' Translation -
629 Set string value... '.i' Sound -
632 Set string value... '.i' Pinyin xie4xie0
633 Set string value... '.i' Character -
634 Set string value... '.i' Translation -
635 Set string value... '.i' Sound -
638 Set string value... '.i' Pinyin zai4jian4
639 Set string value... '.i' Character -
640 Set string value... '.i' Translation -
641 Set string value... '.i' Sound -
642 numberOfWords = Get number of rows
645 call set_window_title 'buttons$' 'wordlistName$'
648 procedure display_word_list_name
652 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
653 call wipeArea 'wipeWordlistArea$'
654 call adjustFontSizeOnHeight 'defaultFontSize' 5
655 .currentFontSize = adjustFontSizeOnHeight.newFontSize
658 demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
661 call set_font_size 'defaultFontSize'
664 procedure write_word_list
666 call draw_tone_contour
668 # Write current Pinyin text
669 call display_text Black
671 # Write the current word list name
672 call display_word_list_name
675 procedure start_logging
676 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
677 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
678 .logDirectory$ = extractWord$(.logDirectory$, "")
679 if .logDirectory$ = "" or not fileReadable(.logDirectory$)
680 .logDirectory$ = "'preferencesDirectory$'/sgc2/log"
682 createDirectory("'.logDirectory$'/sgc2log")
683 currentLogDirectory$ = "'.logDirectory$'/sgc2log/log'logtimeStamp$'"
684 createDirectory(currentLogDirectory$)
685 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
686 .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
687 .headerLine$ > 'currentLogDirectory$'/wordlist.Table
690 config.logPerformance = 1
694 procedure log_performance .recordedSound$ .register .precision .pinyin$ .choice$
696 .currentDate$ = date$()
697 .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
698 .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
700 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
701 .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
702 .logtext$ = .pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
704 fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
706 fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
708 select Sound 'recordedSound$'
709 Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
713 procedure paint_logging_light
715 .row = Search column... Label !Logging
717 exit Button Table Config does not have a row with label !Logging
720 .leftX = Get value... '.row' LeftX
721 .rightX = Get value... '.row' RightX
722 .lowY = Get value... '.row' LowY
723 .highY = Get value... '.row' HighY
724 .buttonColor$ = Get value... '.row' Color
725 .centerX = (.leftX + .rightX)/2
726 .centerY = (.lowY + .highY)/2
727 .radius = (.highY - .lowY )/(4*2)
728 .wipeRadius = 1.1*.radius
729 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
730 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
731 demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
734 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
739 # Uninstall word lists
740 procedure removeWordlist .deletedWordlistName$
742 if fileReadable("'preferencesDirectory$'/sgc2/wordlists/'.deletedWordlistName$'")
743 .targetDir$ = "'preferencesDirectory$'/sgc2/wordlists/'.deletedWordlistName$'"
745 Create Strings as file list... DeleteList '.targetDir$'/*
746 .numdeleteFiles = Get number of strings
747 for .i to .numdeleteFiles
748 .file$ = Get string... '.i'
749 deleteFile("'.targetDir$'/'.file$'")
751 deleteFile("'.targetDir$'")
752 select Strings DeleteList
757 procedure sgc2wordlist .sourceDir$
758 if startsWith(.sourceDir$, "preferencesDirectory$")
759 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
762 .targetDirectory$ = "'preferencesDirectory$'/sgc2/wordlists"
763 if fileReadable(.sourceDir$)
764 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
765 .numFiles = Get number of strings
767 select Strings PackageList
768 .file$ = Get string... '.i'
769 call readWordlist '.sourceDir$' '.file$'
772 select Strings PackageList
777 # Debuggin remarks!!!
778 # fileReadable(<directory>) werkt niet in Windows
779 # De file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
780 # And yet only the 7z decompression has been implemented
781 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z"" x"
782 procedure readWordlist .sourceDir$ .file$
783 # No use doing anything if the source does not exist
784 if fileReadable("'.sourceDir$'/'.file$'")
785 # What will be the target wordlist directory?
786 .targetDirectory$ = "'preferencesDirectory$'/sgc2/wordlists"
787 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
791 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
792 # Wordlist directory does not exist, neither locally nor in the preferences
793 if not (fileReadable(.dirname$) or fileReadable(.wordlistDirectory$))
795 # Move source to destination
796 if index(.file$, ".sgc")
797 # Create wordlist directory
798 createDirectory(.wordlistDirectory$)
801 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
802 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
804 system copy "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"
805 system chdir "'.wordlistDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
807 deleteFile("'.wordlistDirectory$'/'.file$'")
808 elsif index_regex(.file$, "\.(Table|txt)")
809 # Create wordlist directory
810 createDirectory(.wordlistDirectory$)
812 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt)$", "\1", 0)
814 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
816 system copy "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"
818 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt")
819 # Create wordlist directory
820 createDirectory(.wordlistDirectory$)
822 .sourceFiles = Create Strings as file list... SourceStrings '.sourceDir$'/'.file$'/
823 .numFiles = Get number of strings
825 select '.sourceFiles'
826 .currentFile$ = Get string... '.i'
828 system bash -rc -- 'cp "'.sourceDir$'/'.file$'/'.currentFile$'" "'.wordlistDirectory$'/"'
830 system copy "'.sourceDir$'/'.file$'/'.currentFile$'" "'.wordlistDirectory$'/"
833 select '.sourceFiles'
837 # Set current word list to read list
839 wordlistName$ = .dirname$
842 .label$ = "!NotAWordlist"
845 call findLabel '.table$' '.label$'
847 select Table '.table$'
848 .helpText$ = Get value... '.row' Helptext
849 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
850 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
851 # Wait for confirmation