forked from svn2github/freearc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileManDialogs.hs
870 lines (756 loc) · 43.9 KB
/
FileManDialogs.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
{-# OPTIONS_GHC -cpp #-}
----------------------------------------------------------------------------------------------------
---- FreeArc archive manager: Extract/ArcInfo/Settings dialogs ------
----------------------------------------------------------------------------------------------------
module FileManDialogs where
import Prelude hiding (catch)
import Control.Concurrent
import Control.Exception
import Control.Monad
import Control.Monad.Fix
import Data.Char
import Data.IORef
import Data.List
import Data.Maybe
import System.IO.Unsafe
import System.Cmd
#if defined(FREEARC_WIN)
import System.Win32
#endif
import Graphics.UI.Gtk
import Graphics.UI.Gtk.ModelView as New
import Utils
import Errors
import Files
import FileInfo
import Charsets
import Compression
import Encryption
import Options
import UIBase
import UI
import ArhiveStructure
import ArhiveDirectory
import ArcExtract
import FileManPanel
import FileManUtils
----------------------------------------------------------------------------------------------------
---- Äèàëîã ðàñïàêîâêè ôàéëîâ ----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
extractDialog fm' exec cmd arcnames arcdir files = do
fm <- val fm'
title <- i18n$ case (cmd, files, arcnames) of
("t", [], []) -> "0157 Test all archives"
("t", [], [arcname]) -> "0152 Test %3"
("t", [file], [arcname]) -> "0153 Test %1 from %3"
("t", files, [arcname]) -> "0154 Test %2 files from %3"
("t", files, arcnames) -> "0155 Test %4 archives"
(_, [], []) -> "0158 Extract all archives"
(_, [], [arcname]) -> "0024 Extract files from %3"
(_, [file], [arcname]) -> "0025 Extract %1 from %3"
(_, files, [arcname]) -> "0026 Extract %2 files from %3"
(_, files, arcnames) -> "0027 Extract files from %4 archives"
let wintitle = formatn title [head files, show3$ length files, takeFileName$ head arcnames, show3$ length arcnames]
-- Ñîçäàäèì äèàëîã ñî ñòàíäàðòíûìè êíîïêàìè OK/Cancel
fmDialog fm' wintitle [AddDetachButton] $ \(dialog,okButton) -> do
upbox <- dialogGetUpper dialog
; outFrame <- frameNew
; boxPackStart upbox outFrame PackNatural 5 `on` cmd/="t"
; vbox <- vBoxNew False 0
; set outFrame [containerChild := vbox, containerBorderWidth := 5]
(hbox, _, dir) <- fmFileBox fm' dialog
"dir" FileChooserActionSelectFolder
(label "0004 Output directory:")
"0021 Select output directory"
aANYFILE_FILTER
(const$ return True)
(fmCanonicalizeDiskPath fm')
; boxPackStart vbox hbox PackNatural 0
addDirButton <- checkBox "0014 Append archive name to the output directory"
; boxPackStart vbox (widget addDirButton) PackNatural 0
overwrite <- radioFrame "0005 Overwrite mode"
[ "0001 Ask before overwrite",
"0002 Overwrite without prompt",
"0003 Update old files",
"0051 Skip existing files" ]
; boxPackStart upbox (widget overwrite) PackNatural 5 `on` cmd/="t"
(decryption, decryptionOnOK) <- decryptionBox fm' dialog -- Íàñòðîéêè ðàñøèôðîâêè
; boxPackStart upbox decryption PackNatural 5
keepBrokenButton <- fmCheckButtonWithHistory fm' "KeepBroken" False "0425 Keep broken extracted files"
; boxPackStart upbox (widget keepBrokenButton) PackNatural 5 `on` cmd/="t"
(hbox, options, optionsStr) <- fmCheckedEntryWithHistory fm' "xoptions" "0072 Additional options:"
; boxPackStart upbox hbox PackNatural 5
-- Óñòàíîâèì âûõîäíîé êàòàëîã â çíà÷åíèå ïî óìîë÷àíèþ
case arcnames of
[arcname] -> do dir =:: fmCanonicalizeDiskPath fm' (takeBaseName arcname)
_ -> do dir =:: fmCanonicalizeDiskPath fm' "."; addDirButton=:True
widgetShowAll upbox
choice <- fmDialogRun fm' dialog (if cmd/="t" then "ExtractDialog" else "TestDialog")
when (choice `elem` [ResponseOk, aResponseDetach]) $ do
-- Çàïóñòèòü êîìàíäó â îòäåëüíîé êîïèè FreeArc?
let detach = (choice == aResponseDetach)
overwriteOption <- val overwrite
dir' <- val dir; saveHistory dir
isAddDir <- val addDirButton
decryptionOptions <- decryptionOnOK
keepBroken <- val keepBrokenButton
optionsEnabled <- val options
; optionsStr' <- val optionsStr; saveHistory optionsStr `on` optionsEnabled
exec detach$
(arcnames ||| ["*"]) .$map (\arcname ->
[cmd]++
(cmd/="t" &&& (
["-dp"++clear dir']++
(isAddDir &&& ["-ad"])++
(arcdir &&& files &&& ["-ap"++clear arcdir])++
(keepBroken &&& ["-kb"])++
(overwriteOption `select` ",-o+,-u -o+,-o-")))++
decryptionOptions++
["--fullnames"]++
["--noarcext"]++
(optionsEnabled &&& words (clear optionsStr'))++
["--", clear arcname]++files)
----------------------------------------------------------------------------------------------------
---- Äèàëîã èíôîðìàöèè îá àðõèâå -------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
arcinfoDialog fm' exec mode arcnames arcdir files = do
handle (\e -> fmErrorMsg fm' "0013 There are no archives selected!") $ do
fm <- val fm'
let arcname = head arcnames
fm_arc <- case () of _ | isFM_Archive fm -> return (subfm fm)
| otherwise -> with' (newFMArc fm' arcname "") (return) (\_ -> closeFMArc fm')
let archive = subfm_archive fm_arc
title <- i18n"0085 All about %1"
let wintitle = format title (takeFileName arcname)
-- Ñîçäàäèì äèàëîã ñî ñòàíäàðòíûìè êíîïêàìè OK/Cancel
fmDialog fm' wintitle [] $ \(dialog,okButton) -> do
(nb,newPage) <- startNotebook dialog
------ Ãëàâíàÿ çàêëàäêà ----------------------------------------------------------------------------
vbox <- newPage "0174 Main"; let pack n makeControl = do control <- makeControl
boxPackStart vbox control PackNatural n
let filelist = map (cfFileInfo)$ arcDirectory archive
footer = arcFooter archive
dataBlocks = arcDataBlocks archive -- ñïèñîê ñîëèä-áëîêîâ
numOfBlocks = length dataBlocks
empty = "-"
; yes <- i18n"0101 Yes" >>== replaceAll "_" ""
let origsize = sum$ map blOrigSize dataBlocks -- ñóììàðíûé îáú¸ì ôàéëîâ â ðàñïàêîâàííîì âèäå
compsize = sum$ map blCompSize dataBlocks -- ñóììàðíûé îáú¸ì ôàéëîâ â óïàêîâàííîì âèäå
getCompressors = partition isEncryption.blCompressor -- ðàçäåëèòü àëã-ìû øèôðîâàíèÿ è ñæàòèÿ äëÿ áëîêà
(encryptors, compressors) = unzip$ map getCompressors dataBlocks -- ñïèñîê àëã. øèôðîâàíèÿ è ñæàòèÿ.
header_encryptors = deleteIf null$ map (fst.getCompressors) (ftBlocks footer) -- àëãîðèòìû øèôðîâàíèÿ ñëóæåáíûõ áëîêîâ
all_encryptors = deleteIf null encryptors ++ header_encryptors -- à òåïåðü âñå âìåñòå :)
ciphers = joinWith "\n"$ removeDups$ map (join_compressor.map method_name) all_encryptors -- èìåíà àëã. øèôðîâàíèÿ.
formatMem s = x++" "++y where (x,y) = span isDigit$ showMem s
let -- Ìàêñèìàëüíûå ñëîâàðè îñíîâíûõ è âñïîìîãàòåëüíûõ àëãîðèòìîâ
dicts = compressors.$ map (splitAt 1.reverse.map getDictionary) -- [([mainDict],[auxDict1,auxDict2..])...]
.$ map (\([x],ys) -> (x, maximum(0:ys))) -- [(mainDict,maxAuxDict)...]
.$ ((0,0):) .$ sort .$ last -- Âûáèðàåì ñòðî÷êó ñ ìàêñ. îñíîâíûì è âñïîì. ñëîâàð¸ì
dictionaries = case dicts of
(0,0) -> empty
(maxMainDict, 0) -> formatMem maxMainDict
(maxMainDict, maxAuxDict) -> showMem maxAuxDict++" + "++showMem maxMainDict
pack 10 $twoColumnTable [("0173 Directories:", show3$ ftDirs$ subfm_filetree fm_arc)
,("0088 Files:", show3$ ftFiles$ subfm_filetree fm_arc)
,("0089 Total bytes:", show3$ origsize)
,("0090 Compressed bytes:", show3$ compsize)
,("0091 Ratio:", ratio3 compsize origsize++"%")]
pack 0 $twoColumnTable [("0104 Directory blocks:", show3$ length$ filter ((DIR_BLOCK==).blType) (ftBlocks footer))
,("0092 Solid blocks:", show3$ numOfBlocks)
,("0093 Avg. blocksize:", formatMem$ origsize `div` i(max numOfBlocks 1))]
pack 10 $twoColumnTable [("0099 Compression memory:", formatMem$ maximum$ 0: map compressionGetShrinkedCompressionMem compressors)
,("0100 Decompression memory:", formatMem$ maximum$ 0: map compressionGetShrinkedDecompressionMem compressors)
,("0105 Dictionary:", dictionaries)]
pack 0 $twoColumnTable [("0094 Archive locked:", ftLocked footer &&& yes ||| empty)
,("0098 Archive comment:", ftComment footer &&& yes ||| empty)
,("0095 Recovery info:", ftRecovery footer ||| empty)
,("0096 SFX size:", ftSFXSize footer .$show3 .$changeTo [("0", empty)])
,("0156 Headers encrypted:", header_encryptors &&& yes ||| empty)]
table <- twoColumnTable [("0097 Encryption algorithms:", ciphers ||| empty)]
boxPackStart vbox table PackNatural (ciphers &&& 10)
------ Çàêëàäêà òåõ. ñîäåðæàíèÿ àðõèâà -------------------------------------------------------------
vBox <- newPage "0449 Solid blocks"
let columnTitles = ["0450 Position", "0451 Size", "0452 Compressed", "0453 Files", "0454 Method"]
n = map (drop 5) columnTitles
s <- i18ns columnTitles
let compressor = join_compressor.blCompressor
(listUI, listView, listModel, listSelection, columns, onColumnTitleClicked) <-
createListView compressor [(n!!0, s!!0, (show3.blPos), [cellXAlign := 1]),
(n!!1, s!!1, (show3.blOrigSize), [cellXAlign := 1]),
(n!!2, s!!2, (show3.blCompSize), [cellXAlign := 1]),
(n!!3, s!!3, (show3.blFiles), [cellXAlign := 1]),
(n!!4, s!!4, (compressor), [])]
boxPackStart vBox listUI PackGrow 0
for columns $ \(name,col1) -> do New.treeViewColumnSetFixedWidth col1 100
changeList listModel listSelection dataBlocks
------ Çàêëàäêà êîììåíòàðèÿ àðõèâà -----------------------------------------------------------------
vbox <- newPage "0199 Comment"
comment <- scrollableTextView (ftComment footer) []
boxPackStart vbox (widget comment) PackGrow 0
widgetShowAll dialog
notebookSetCurrentPage nb 1 `on` mode==CommentMode
choice <- fmDialogRun fm' dialog "ArcInfoDialog"
when (choice==ResponseOk) $ do
newComment <- val comment
when (newComment /= ftComment footer) $ do
exec False [["ch"
,"--noarcext"
,newComment &&& ("--archive-comment="++newComment)
||| "-z-"
,"--"
,arcname]]
----------------------------------------------------------------------------------------------------
---- Äèàëîã íàñòðîåê ïðîãðàììû ---------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
settingsDialog fm' = do
fm <- val fm'
fmDialog fm' "0067 Settings" [] $ \(dialog,okButton) -> do
(nb,newPage) <- startNotebook dialog
------ Ãëàâíàÿ çàêëàäêà ----------------------------------------------------------------------
vbox <- newPage "0174 Main"; let pack x = boxPackStart vbox x PackNatural 1
aboutLabel <- labelNewWithMnemonic aARC_HEADER_WITH_DATE
langLabel <- label "0068 Language:"
langComboBox <- New.comboBoxNewText
editLangButton <- button "0069 Edit"
convertLangButton <- button "0070 Import"
-- Ëîãôàéë
(logfileBox, _, logfile) <- fmFileBox fm' dialog
"logfile" FileChooserActionSave
(label "0166 Logfile:")
"0167 Select logfile"
aANYFILE_FILTER
(const$ return True)
(fmCanonicalizeDiskPath fm')
; viewLogfileButton <- button "0292 View"
-- Êàòàëîã äëÿ âðåìåííûõ ôàéëîâ
(tempdirBox, _, tempdir) <- fmFileBox fm' dialog
"tempdir" FileChooserActionSelectFolder
(label "0447 Temporary directory:")
"0448 Select directory for temporary files"
aANYFILE_FILTER
(const$ return True)
(fmCanonicalizeDiskPath fm')
-- Ïðî÷åå
toolbarTextButton <- fmCheckButtonWithHistory fm' "ToolbarCaptions" True "0361 Add captions to toolbar buttons"
checkNewsButton <- fmCheckButtonWithHistory fm' "CheckNews" True "0370 Watch for new versions via Internet"
notes <- label . joinWith "\n" =<<
i18ns["0168 You should restart FreeArc in order for a language settings to take effect.",
"0169 Passwords need to be entered again after restart."]
-----------------------------------------------------------------------------------------------
-- Èíôîðìàöèÿ î òåêóùåì ÿçûêå ëîêàëèçàöèè
langTable <- tableNew 2 2 False
let dataset = [("0170 Full name:", "0000 English"), ("0171 Copyright:", "0159 ")]
labels <- foreach [0..1] $ \y -> do
-- Ïåðâàÿ êîëîíêà
label1 <- labelNew Nothing; let x=0
tableAttach langTable label1 (x+0) (x+1) y (y+1) [Fill] [Fill] 5 5
miscSetAlignment label1 0 0
-- Âòîðàÿ êîëîíêà
label2 <- labelNew Nothing
tableAttach langTable label2 (x+1) (x+2) y (y+1) [Expand, Fill] [Expand, Fill] 5 5
set label2 [labelSelectable := True]
miscSetAlignment label2 0 0
return (label1, label2)
--
let showLang i18n = do
for (zip labels dataset) $ \((l1,l2),(s1,s2)) -> do
labelSetTextWithMnemonic l1 =<< i18n s1
labelSetMarkup l2.bold =<< i18n s2
--
showLang i18n
-- Òåêóùèå íàñòðîéêè
inifile <- findFile configFilePlaces aINI_FILE
settings <- inifile &&& readConfigFile inifile >>== map (split2 '=')
let langFile = settings.$lookup aINITAG_LANGUAGE `defaultVal` ""
-- Çàïîëíèòü ñïèñîê ÿçûêîâ èìåíàìè ôàéëîâ â êàòàëîãå arc.languages è âûáðàòü àêòèâíûé ÿçûê
langDir <- findDir libraryFilePlaces aLANG_DIR
langFiles <- langDir &&& (dir_list langDir >>== map baseName >>== sort >>== filter (match "arc.*.txt"))
-- Îòîáðàçèì ÿçûêè â 5 ñòîëáöîâ, ñ ñîðòèðîâêîé ïî ñòîëáöàì
let cols = 5
; langComboBox `New.comboBoxSetWrapWidth` cols
let rows = (length langFiles) `divRoundUp` cols; add = rows*cols - length langFiles
sortOnColumn x = r*cols+c where (c,r) = x `divMod` rows -- ïåðåñ÷èòàòü èç ïîêîëîíî÷íûõ ïîçèöèé â ïîñòðî÷íûå
; langFiles <- return$ map snd $ sort $ zip (map sortOnColumn [0..]) (langFiles ++ replicate add "")
--
for langFiles (New.comboBoxAppendText langComboBox . mapHead toUpper . replace '_' ' ' . dropEnd 4 . drop 4)
whenJust_ (elemIndex (takeFileName langFile) langFiles)
(New.comboBoxSetActive langComboBox)
-- Îïðåäåëèòü ôàéë ëîêàëèçàöèè, ñîîòâåòñòâóþùèé âûáðàííîìó â êîìáîáîêñå ÿçûêó
let getCurrentLangFile = do
lang <- New.comboBoxGetActive langComboBox
case lang of
Just lang -> myCanonicalizePath (langDir </> (langFiles !! lang))
Nothing -> return ""
-- Ïðè âûáîðå äðóãîãî ÿçûêà ëîêàëèçàöèè âûâåñòè èíôîðìàöèþ î í¸ì
langComboBox `New.onChanged` do
whenJustM_ (New.comboBoxGetActive langComboBox) $ \_ -> do
langFile <- getCurrentLangFile
localeInfo <- parseLocaleFile langFile
showLang (i18n_general (return localeInfo) .>>== fst)
-- Ðåäàêòèðîâàíèå òåêóùåãî ôàéëà ëîêàëèçàöèè/ëîãôàéëà
editLangButton `onClick` (runEditCommand =<< getCurrentLangFile)
viewLogfileButton `onClick` (runViewCommand =<< val logfile)
; langFrame <- frameNew
; vbox1 <- vBoxNew False 0
; set langFrame [containerChild := vbox1, containerBorderWidth := 5]
; langbox <- hBoxNew False 0
boxPackStart langbox (widget langLabel) PackNatural 0
boxPackStart langbox langComboBox PackGrow 5
boxPackStart langbox (widget editLangButton) PackNatural 5
--boxPackStart langbox (widget convertLangButton) PackNatural 5
boxPackStart vbox1 langbox PackNatural 5
boxPackStart vbox1 langTable PackNatural 5
boxPackStart logfileBox (widget viewLogfileButton) PackNatural 5
boxPackStart vbox aboutLabel PackNatural 5
boxPackStart vbox langFrame PackNatural 5
boxPackStart vbox logfileBox PackNatural 5
boxPackStart vbox tempdirBox PackNatural 5
boxPackStart vbox (widget toolbarTextButton) PackNatural 5
boxPackStart vbox (widget checkNewsButton) PackNatural 5
boxPackStart vbox (widget notes) PackNatural 5
------ Çàêëàäêà èíòåãðàöèè ñ Explorer ---------------------------------------------------------
#if defined(FREEARC_WIN)
vbox <- newPage "0421 Explorer integration"; let pack x = boxPackStart vbox x PackNatural 1
associateButton <- fmCheckButtonWithHistory fm' "Settings.Associate" True "0172 Associate FreeArc with .arc files"
contextMenuButton <- fmCheckButtonWithHistory fm' "Settings.ContextMenu" True "0422 Enable context menu in Explorer"
cascadedButton <- fmCheckButtonWithHistory fm' "Settings.ContextMenu.Cascaded" True "0423 Make it cascaded"
empty <- label ""
pack (widget associateButton)
pack (widget empty)
frame <- frameNew; frameSetLabelWidget frame (widget contextMenuButton)
boxPackStart vbox frame PackGrow 1
hbox <- hBoxNew False 0; containerAdd frame hbox
let show_or_hide = widgetSetSensitivity hbox =<< val contextMenuButton
show_or_hide
show_or_hide .$ setOnUpdate contextMenuButton
oldContextMenu <- val contextMenuButton
vbox <- vBoxNew False 0; boxPackStart hbox vbox PackGrow 10
let pack x = boxPackStart vbox x PackNatural 1
empty <- label ""
notes <- label =<< i18n"0424 Enable individual commands:"
pack (widget cascadedButton)
pack (widget empty)
pack (widget notes)
-- Put all subsequent checkboxes to scrolled window
scrolledWindow <- scrolledWindowNew Nothing Nothing
boxPackStart vbox scrolledWindow PackGrow 1
vbox <- vBoxNew False 0
scrolledWindowAddWithViewport scrolledWindow vbox
scrolledWindowSetPolicy scrolledWindow PolicyAutomatic PolicyAutomatic
Just viewport <- binGetChild scrolledWindow
viewportSetShadowType (castToViewport viewport) ShadowNone
let pack x = boxPackStart vbox x PackNatural 1
let makeButton ("",_,_) = do pack =<< hSeparatorNew; return []
makeButton (cmdname,itext,imsg) = do
button <- fmCheckButtonWithHistory fm' ("Settings.ContextMenu.Command."++cmdname) True imsg
pack (widget button)
return [button]
commands <- getExplorerCommands >>= concatMapM makeButton
#endif
------ Çàêëàäêà ñæàòèÿ ------------------------------------------------------------------------
(_, saveCompressionHistories) <- compressionPage fm' =<< newPage "0106 Compression"
------ Çàêëàäêà øèôðîâàíèÿ --------------------------------------------------------------------
(_, saveEncryptionHistories) <- encryptionPage fm' dialog okButton =<< newPage "0119 Encryption"
------ Çàêëàäêà èíôîðìàöèè î ñèñòåìå ----------------------------------------------------------
vbox <- newPage "0388 Info"; let pack n makeControl = do control <- makeControl
boxPackStart vbox control PackNatural n
maxBlock <- getMaxMemToAlloc
pack 10 $twoColumnTable [("0389 Largest contiguous free memblock:", showMem (maxBlock `roundDown` mb))]
-----------------------------------------------------------------------------------------------
widgetShowAll dialog
choice <- fmDialogRun fm' dialog "SettingsDialog"
when (choice==ResponseOk) $ do
-- Ñîõðàíÿåì íàñòðîéêè â INI-ôàéë, ïàðîëè - â ãëîá. ïåðåìåííûõ, keyfile - â èñòîðèè
langFile <- getCurrentLangFile
inifile <- findOrCreateFile configFilePlaces aINI_FILE
buildPathTo inifile
saveConfigFile inifile$ map (join2 "=") [(aINITAG_LANGUAGE, takeFileName langFile)]
loadTranslation
saveHistory `mapM_` [logfile, tempdir]
saveHistory `mapM_` [toolbarTextButton, checkNewsButton]
saveCompressionHistories
saveEncryptionHistories ""
#if defined(FREEARC_WIN)
saveHistory `mapM_` ([associateButton, contextMenuButton, cascadedButton] ++ commands)
registerShellExtensions (Just oldContextMenu)
#endif
return ()
----------------------------------------------------------------------------------------------------
---- (Äå)ðåãèñòðàöèÿ shell extension ---------------------------------------------------------------
----------------------------------------------------------------------------------------------------
#if defined(FREEARC_WIN)
translateExplorerCommand (cmdname,etext,emsg) = do [itext,imsg] <- i18ns [etext,emsg]
return (cmdname, itext, imsg)
-- |Âîçâðàùàåò ñïèñîê ëîêàëèçîâàííûõ îïèñàíèé êîìàíä, èíòåãðèðóåìûõ â Explorer
getExplorerCommands = mapM translateExplorerCommand$
[ ("add2arc" , "0391 Add to \"%s\"" , "0392 Compress the selected files using FreeArc" )
, ("add2sfx" , "0393 Add to SFX \"%s\"" , "0394 Compress the selected files into SFX using FreeArc" )
, ("add" , "0395 Add to archive..." , "0396 Compress the selected files using FreeArc via dialog")
, ("" , "" , "" )
, ("open" , "0397 Open with FreeArc" , "0398 Open the selected archive(s) with FreeArc" )
, ("extractTo" , "0399 Extract to \"%s\"" , "0400 Extract the selected archive(s) to new folder" )
, ("extractHere", "0401 Extract here" , "0402 Extract the selected archive(s) to the same folder" )
, ("extract" , "0403 Extract..." , "0404 Extract the selected archive(s) via dialog" )
, ("test" , "0405 Test" , "0406 Test the selected archive(s)" )
, ("" , "" , "" )
, ("arc2sfx" , "0407 Convert to SFX" , "0408 Convert the selected archive(s) to SFX" )
, ("sfx2arc" , "0409 Convert from SFX" , "0410 Convert the selected SFX(es) to normal archive(s)" )
, ("" , "" , "" )
, ("modify" , "0411 Modify..." , "0412 Modify the selected archives via dialog" )
, ("join" , "0413 Join..." , "0414 Join the selected archives via dialog" )
, ("" , "" , "" )
, ("zip2arc" , "0415 Convert to .arc" , "0416 Convert the selected archive(s) to FreeArc format" )
, ("zip2sfx" , "0417 Convert to .arc SFX", "0418 Convert the selected archive(s) to FreeArc SFX" )
, ("zip2a" , "0419 Convert to .arc..." , "0420 Convert the selected archive(s) to FreeArc format via dialog")
]
-- |Ðåãèñòðàöèÿ
registerShellExtensions oldContextMenu = do
hf' <- openHistoryFile
hfCacheConfigFile hf' $ do
associate <- hfGetHistoryBool hf' "Settings.Associate" True
contextMenu <- hfGetHistoryBool hf' "Settings.ContextMenu" True
cascaded <- hfGetHistoryBool hf' "Settings.ContextMenu.Cascaded" True
commands <- getExplorerCommands >>== filter(not.null.fst3)
cmdEnabled <- foreach commands $ \(cmdname,itext,imsg) ->
hfGetHistoryBool hf' ("Settings.ContextMenu.Command."++cmdname) True
changeRegistrationOfShellExtensions hf' associate oldContextMenu contextMenu cascaded cmdEnabled commands
-- |Óäàëåíèå ðåãèñòðàöèè
unregisterShellExtensions = do
hf' <- openHistoryFile
hfCacheConfigFile hf' $ do
changeRegistrationOfShellExtensions hf' False Nothing False undefined undefined undefined
-- |Èçìåíåíèå íàñòðîåê ðåãèñòðàöèè
changeRegistrationOfShellExtensions hf' associate oldContextMenu contextMenu cascaded cmdEnabled commands = do
exe <- getExeName -- Name of FreeArc.exe file
let ico = exe `replaceExtension` ".ico" -- Name of FreeArc.ico file
dir = exe.$takeDirectory -- FreeArc.exe directory
shext = dir </> "ArcShellExt" -- Shell extension directory
empty = dir </> "empty.arc" -- Name of empty archive file
register = registrySetStr hKEY_CLASSES_ROOT
version = aARC_VERSION_WITH_DATE
old_shext <- hfGetHistory1 hf' "Settings.ContextMenu.Directory" ""
hfReplaceHistory hf' "Settings.ContextMenu.Directory" shext
old_version <- hfGetHistory1 hf' "Settings.ContextMenu.Version" ""
hfReplaceHistory hf' "Settings.ContextMenu.Version" version
-- (Un)registering ArcShellExt dlls - performed only if setting were changed
let dll_register mode = when ((oldContextMenu,old_shext,old_version) /= (Just contextMenu,shext,version)) $ do
runProgram$ "regsvr32 "++mode++" /s /c \""++(shext </> "ArcShellExt.dll\"")
runProgram$ "regsvr32 "++mode++" /s /c \""++(shext </> "ArcShellExt-64.dll\"")
return ()
-- First, unregister any old version
dll_register "/u"
registryDeleteTree hKEY_CLASSES_ROOT "*\\shell\\FreeArc"
registryDeleteTree hKEY_CLASSES_ROOT "Directory\\shell\\FreeArc"
registryDeleteTree hKEY_CLASSES_ROOT ".arc"
registryDeleteTree hKEY_CLASSES_ROOT "FreeArc.arc"
-- This part is performed only when Association enabled
when associate $ do
register "FreeArc.arc" "" "FreeArc archive"
register "FreeArc.arc\\DefaultIcon" "" (ico++",0")
register "FreeArc.arc\\shell" "" "open"
register "FreeArc.arc\\shell\\open\\command" "" ("\""++exe++"\" \"%1\"")
register ".arc" "" "FreeArc.arc"
register ".arc\\ShellNew" "FileName" empty
-- This part is performed only when Context Menu is enabled
when contextMenu $ do
-- Generate ArcShellExt config script
all2arc <- all2arc_path
let q str = "\"" ++ str.$replaceAll "\"" "\\\"" ++ "\""
let script = [ "-- This file uses UTF8 encoding without BOM"
, ""
, "-- 1 for cascaded menus, nil for flat"
, "cascaded = "++(iif cascaded "1" "nil")
, ""
, "-- Commands"
, "command = {}"
] ++ zipWith (\enabled (cmdname,text,help) ->
(not enabled &&& "-- ")++"command."++cmdname++" = {text = "++q text++", help = "++q help++"}")
cmdEnabled commands ++
[ ""
, "-- Path to FreeArc"
, "freearc = \"\\\""++(exe.$replaceAll "\\" "\\\\")++"\\\"\""
, ""
, "-- Path to All2Arc"
, "all2arc = \"\\\""++(all2arc.$replaceAll "\\" "\\\\")++"\\\"\""
]
saveConfigFile (shext </> "ArcShellExt-config.lua") script
-- Register DLL
dll_register ""
return ()
#else
registerShellExtensions = doNothing
unregisterShellExtensions = doNothing0
#endif
----------------------------------------------------------------------------------------------------
---- Çàêëàäêà ñæàòèÿ -------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
compressionPage fm' vbox = do
let pack x = boxPackStart vbox x PackNatural 1
-- Àëãîðèòì ñæàòèÿ.
(hbox, cmethod) <- fmLabeledEntryWithHistory fm' "compression" "0175 Compression profile:"; pack hbox
; save <- button "0178 Save"; boxPackStart hbox (widget save) PackNatural 5
-- Íàñòðîéêè àëãîðèòìà ñæàòèÿ.
hbox <- hBoxNew False 0; pack hbox
; method <- radioFrame "0107 Compression level" levels; boxPackStart hbox (widget method) PackNatural 0
; methodText <- labelNew Nothing; boxPackStart hbox methodText PackGrow 0
xMethod <- checkBox "0113 Fast, low-memory decompression"; pack (widget xMethod)
autodetect <- checkBox "0176 Filetype auto-detection" ; pack (widget autodetect)
-- Íàñòðîéêè ðàçìåðà ñîëèä-áëîêà
vbox1 <- vBoxNew False 0; let pack1 x = boxPackStart vbox1 x PackNatural 1
; (hbox, solidBytesOn, solidBytes) <- fmCheckedEntryWithHistory fm' "bytes" "0138 Bytes, no more than:"; pack1 hbox
; (hbox, solidFilesOn, solidFiles) <- fmCheckedEntryWithHistory fm' "files" "0139 Files, no more than:"; pack1 hbox
; solidByExtension <- checkBox "0140 Split by extension" ; pack1 (widget solidByExtension)
solidBlocksFrame <- frameNew; pack solidBlocksFrame; s <- i18n"0177 Limit solid blocks"
set solidBlocksFrame [containerChild := vbox1, frameLabel := s, containerBorderWidth := 5]
-- Èíèöèàëèçàöèÿ ïîëåé
let m=4; x=False
method =: (6-m) .$ clipTo 0 5
xMethod =: x
autodetect =: True
-- Îïóáëèêîâàòü îïèñàíèå ïåðâîíà÷àëüíî âûáðàííîãî ìåòîäà ñæàòèÿ è îáíîâëÿòü åãî ïðè èçìåíåíèÿõ íàñòðîåê
let parsePhysMem = parseMemWithPercents (toInteger getPhysicalMemory `roundTo` (4*mb))
let getSimpleMethod = do
m <- val method
x <- val xMethod
return$ show(if m==0 then 9 else 6-m)++(x.$bool "" "x")
let describeMethod = do
m <- val method
x <- val xMethod
methodName <- getSimpleMethod
let compressor = methodName.$ decode_method []
.$ limitCompressionMem (parsePhysMem "75%")
.$ limitDecompressionMem (1*gb)
cmem = compressor.$ compressorGetShrinkedCompressionMem
dmem = compressor.$ compressorGetShrinkedDecompressionMem
let level = " ccm uharc 7-zip rar ace zip"
cspeed = x.$bool " 3mb/s 3mb/s 4mb/s 10mb/s 20mb/s 50mb/s" --m9,m5..m1
" 2.5mb/s 2.5mb/s 4mb/s 8mb/s 15mb/s 50mb/s" --m9x,m5x..m1x
dspeed = x.$bool " 4-40mb/s 4-40mb/s 4-40mb/s 25mb/s 40mb/s 100mb/s" --m9,m5..m1
" 40mb/s 40mb/s 40mb/s 40mb/s 60mb/s 100mb/s" --m9x,m5x..m1x
labelSetMarkup methodText . deleteIf (=='_') . unlines =<< mapM i18fmt
[ ["0114 Compression level: %1", bold((words level!!m).$replace '_' ' ')]
, ["0115 Compression speed: %1, memory: %2", bold(words cspeed!!m), bold(showMem cmem)]
, ["0116 Decompression speed: %1, memory: %2", bold(words dspeed!!m), bold(showMem dmem)]
, [""]
, ["0390 All speeds were measured on 3GHz Core2Duo"]]
w1 <- i18n (levels!!m)
w2 <- i18n "0226 (fast, low-memory decompression)"
autodetect' <- val autodetect
solidBytesOn' <- val solidBytesOn
solidBytes' <- val solidBytes
solidFilesOn' <- val solidFilesOn
solidFiles' <- val solidFiles
solidByExtension' <- val solidByExtension
let s = (solidBytesOn' &&& solidBytes')++
(solidFilesOn' &&& (solidFiles'++"f"))++
(solidByExtension' &&& "e")
cmethod =: w1++(x&&&" "++w2)++": "++"-m"++(methodName.$changeTo [("9","x")])++(not autodetect' &&& " -ma-")++(s &&& " -s"++s)
--
describeMethod
describeMethod .$ setOnUpdate xMethod
describeMethod .$ setOnUpdate method
describeMethod .$ setOnUpdate autodetect
describeMethod .$ setOnUpdate solidBytesOn
describeMethod .$ setOnUpdate solidBytes
describeMethod .$ setOnUpdate solidFilesOn
describeMethod .$ setOnUpdate solidFiles
describeMethod .$ setOnUpdate solidByExtension
-- Ñîõðàíåíèå èñòîðèè ñòðîêîâûõ ïîëåé è îáðàáîòêà íàæàòèÿ íà Save
let saveHistories = do
whenM (val solidBytesOn) $ do saveHistory solidBytes
whenM (val solidFilesOn) $ do saveHistory solidFiles
save `onClick` do saveHistories; saveHistory cmethod
-- Âîçâðàòèì ìåòîä íàçíà÷åíèÿ ðåàêöèè íà èçìåíåíèå íàñòðîéêè ñæàòèÿ è ïðîöåäóðó, âûïîëíÿåìóþ ïðè íàæàòèè íà OK
return (\act -> setOnUpdate cmethod (val cmethod >>= act), saveHistories)
{-
let simpleMethod = initSetting "simpleMethod" `defaultVal` "4"
m = case (take 1 simpleMethod) of [d] | isDigit d -> digitToInt d
_ -> 4
x = drop 1 simpleMethod == "x"
; solidBytes' <- val solidBytes; solidBytes' !~ "*b" &&& solidBytes =: solidBytes'++"b"
simpleMethod' <- getSimpleMethod
-}
-- |Compression level names
levels = [ "0108 Maximum",
"0109 High",
"0110 Normal",
"0111 Fast",
"0112 Very fast",
"0127 HDD-speed"]
----------------------------------------------------------------------------------------------------
---- Çàêëàäêà øèôðîâàíèÿ -------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
encryptionPage fm' dialog okButton vbox = do
let pack x = boxPackStart vbox x PackNatural 1
(hbox, pwds) <- pwdBox 2; pack hbox -- Ñîçäà¸ò òàáëèöó ñ ïîëÿìè äëÿ ââîäà äâóõ ïàðîëåé
-- Ôðåéì øèôðîâàíèÿ.
vbox1 <- vBoxNew False 0
frame <- frameNew; s <- i18n"0119 Encryption"
set frame [containerChild := vbox1, frameLabel := s, containerBorderWidth := 5]
let pack1 x = boxPackStart vbox1 x PackNatural 1
boxPackStart vbox frame PackNatural 10
-- Àëãîðèòì øèôðîâàíèÿ.
(hbox, method) <- fmLabeledEntryWithHistory fm' "encryption" "0179 Encryption profile:"; pack1 hbox
; save <- button "0180 Save"; boxPackStart hbox (widget save) PackNatural 0
-- Íàñòðîéêè øèôðîâàíèÿ.
encryptHeaders <- checkBox "0120 Encrypt archive directory"; pack1 (widget encryptHeaders)
usePwd <- checkBox "0181 Use password"; pack1 (widget usePwd)
(hbox, keyfileOn, keyfile) <- fmFileBox fm' dialog
"akeyfile" FileChooserActionOpen
(checkBox "0123 Keyfile:")
"0124 Select keyfile"
aANYFILE_FILTER
(const$ return True)
(fmCanonicalizeDiskPath fm')
; createKeyfile <- button "0125 Create"
; boxPackStart hbox (widget createKeyfile) PackNatural 0; pack1 hbox
(hbox, encAlg) <- fmLabeledEntryWithHistory fm' "encryptor" "0121 Encryption algorithm:"; pack1 hbox
-- Íàñòðîéêè ðàñøèôðîâêè
(decryption, decryptionOnOK) <- decryptionBox fm' dialog
; boxPackStart vbox decryption PackNatural 10
-- Ðàçðåøàåì íàæàòü OK òîëüêî åñëè îáà ââåä¸ííûõ ïàðîëÿ îäèíàêîâû
let [pwd1,pwd2] = pwds
for pwds $ flip afterKeyRelease $ \e -> do
[pwd1', pwd2'] <- mapM val pwds
okButton `widgetSetSensitivity` (pwd1'==pwd2')
return False
-- Ñîçäàòü íîâûé ôàéë-êëþ÷, çàïèñàâ êðèïòîãðàôè÷åñêè ñëó÷àéíûå äàííûå â óêàçàííûé ïîëüçîâàòåëåì ôàéë
createKeyfile `onClick` do
let default_keyfile = do fm <- val fm'; return$ fm_curdir fm </> "new.key"
chooseFile dialog FileChooserActionSave "0126 Create new keyfile" aANYFILE_FILTER default_keyfile $ \filename -> do
--to do: fileChooserSetDoOverwriteConfirmation chooserDialog True
filePutBinary filename =<< generateRandomBytes 1024
keyfile =: filename
keyfileOn =: True
-- Èíèöèàëèçàöèÿ: ïðî÷èòàåì ïàðîëè èç ãëîáàëüíûõ ïåðåìåííûõ
pwd1 =:: val encryptionPassword
pwd2 =:: val encryptionPassword
-- Ñîõðàíåíèå èñòîðèè ñòðîêîâûõ ïîëåé è îáðàáîòêà íàæàòèÿ íà Save
let saveHistories = do
whenM (val keyfileOn) $ do saveHistory keyfile
saveHistory encAlg
save `onClick` do saveHistories; saveHistory method
-- Äåéñòâèÿ, âûïîëíÿåìûå ïðè íàæàòèè íà OK. Âîçâðàùàåò îïöèè, êîòîðûå íóæíî äîáàâèòü â êîìàíäíóþ ñòðîêó
let onOK encryption = do
saveHistories
pwd' <- val pwd1; encryptionPassword =: pwd'
decryptionOptions <- decryptionOnOK
return$ decryptionOptions ++ ((words encryption `contains` "-p?") &&& pwd' &&& ["-p"++pwd'])
-- Ôîðìèðóåò ïðîôèëü øèôðîâàíèÿ è âûçûâàåòñÿ ïðè èçìåíåíèè ëþáûõ îïöèé â ýòîì ôðåéìå
let makeProfile = do
usePwd' <- val usePwd
keyfileOn' <- val keyfileOn
keyfile' <- val keyfile
encAlg' <- val encAlg
encryptHeaders' <- val encryptHeaders
method =: unwords( (encryptHeaders' &&& ["-hp"])++
(usePwd' &&& ["-p?"])++
["--encryption="++clear encAlg']++
(keyfileOn' &&& ["--keyfile=" ++clear keyfile']))
--
makeProfile
makeProfile .$ setOnUpdate usePwd
makeProfile .$ setOnUpdate keyfileOn
makeProfile .$ setOnUpdate keyfile
makeProfile .$ setOnUpdate encAlg
makeProfile .$ setOnUpdate encryptHeaders
-- Âîçâðàòèì ìåòîä íàçíà÷åíèÿ ðåàêöèè íà èçìåíåíèå íàñòðîåê øèôðîâàíèÿ è ïðîöåäóðó, âûïîëíÿåìóþ ïðè íàæàòèè íà OK
return (\act -> setOnUpdate method (val method >>= act), onOK)
----------------------------------------------------------------------------------------------------
---- Ôðåéì ðàñøèôðîâêè -----------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
decryptionBox fm' dialog = do
vbox <- vBoxNew False 0
decryptionFrame <- frameNew; s <- i18n"0144 Decryption"
set decryptionFrame [containerChild := vbox, frameLabel := s, containerBorderWidth := 5]
lbl <- label "0074 Enter password:"
pwd <- entryNew --newTextViewWithText
; set pwd [entryVisibility := False, entryActivatesDefault := True]
(keyfileBox, _, keyfile) <- fmFileBox fm' dialog
"keyfile" FileChooserActionOpen
(label "0123 Keyfile:")
"0124 Select keyfile"
aANYFILE_FILTER
(const$ return True)
(fmCanonicalizeDiskPath fm')
hbox <- hBoxNew False 0
; boxPackStart hbox (widget lbl) PackNatural 0
; boxPackStart hbox pwd PackGrow 5
boxPackStart vbox hbox PackNatural 0
boxPackStart vbox keyfileBox PackNatural 5
-- Ïðî÷èòàåì ïàðîëè èç ãëîáàëüíûõ ïåðåìåííûõ
pwd =:: val decryptionPassword
-- Äåéñòâèå, âûïîëíÿåìîå ïðè íàæàòèè íà OK. Âîçâðàùàåò îïöèè, êîòîðûå íóæíî äîáàâèòü ê êîìàíäíîé ñòðîêå
let onOK = do
pwd' <- val pwd; decryptionPassword =: pwd'
keyfile' <- val keyfile; saveHistory keyfile
return$ (pwd' &&& ["-op"++pwd'])++
(keyfile' &&& ["--OldKeyfile="++clear keyfile'])
return (decryptionFrame, onOK)
----------------------------------------------------------------------------------------------------
---- Âñïîìîãàòåëüíûå îïðåäåëåíèÿ -------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- |Ðåæèìû äèàëîãîâ
data DialogMode = EncryptionMode | ProtectionMode | RecompressMode | CommentMode | MakeSFXMode | NoMode deriving Eq
-- |Îïðåäåëÿåò òî, êàê èìåíà êàòàëîãîâ ïîäñòàâëÿþòñÿ â êîìàíäû
addCmdFiles dirname = [dirname++"/"]
xCmdFiles dirname = [dirname++"/*"]
-- |Âûïîëíèòü îïåðàöèþ íàä òåêóùèì àðõèâîì/âñåìè îòìå÷åííûìè ôàéëàìè íà äèñêå
compressionOperation fm' action exec cmd mode = do
fm <- val fm'
files <- if isFM_Archive fm then return [fm_arcname fm]
else getSelection fm' addCmdFiles -- todo: j/ch êîãäà Selection âêëþ÷àåò êàòàëîãè
action fm' exec cmd files mode
-- |Âûïîëíèòü îïåðàöèþ íàä âûáðàííûìè ôàéëàìè â àðõèâå/âñåìè ôàéëàìè â âûáðàííûõ àðõèâàõ
archiveOperation fm' action = do
fm <- val fm'
files <- getSelection fm' (if isFM_Archive fm then xCmdFiles else const [])
if isFM_Archive fm
then action [fm_arcname fm] (fm_arcdir fm) files
else do fullnames <- mapM (fmCanonicalizePath fm') files
action fullnames "" []
-- |Âûïîëíÿåò îïåðàöèþ, êîòîðîé íóæíî ïåðåäàòü òîëüêî èìåíà àðõèâîâ
multiArchiveOperation fm' action = do
fm <- val fm'
if isFM_Archive fm
then action [fm_arcname fm]
else do files <- getSelection fm' (const [])
fullnames <- mapM (fmCanonicalizePath fm') files
action fullnames
-- |Îáíîâèòü ñîäåðæèìîå ïàíåëè ôàéë-ìåíåäæåðà àêòóàëüíûìè äàííûìè
refreshCommand fm' = do
fm <- val fm'
curfile <- fmGetCursor fm'
selected <- getSelection fm' (:[])
-- Îáíîâèì ñîäåðæèìîå êàòàëîãà/àðõèâà è âîññòàíîâèì òåêóùèé ôàéë è ñïèñîê îòìå÷åííûõ
closeFMArc fm'
chdir fm' (fm_current fm)
when (selected>[]) $ do
fmSetCursor fm' curfile
fmUnselectAll fm'
fmSelectFilenames fm' ((`elem` selected).fmname)
-- |Ïðîñìîòðåòü ôàéë
runViewCommand = runEditCommand
-- |Ðåäàêòèðîâàòü ôàéë
runEditCommand filename = run (iif isWindows "notepad" "gedit") [filename]
where run cmd params = forkIO (rawSystem cmd params >> return ()) >> return ()
-- edit filename | isWindows && takeExtension filename == "txt" = todo: direct shell open command
-- Ïîìåñòèì âñå êîíòðîëû â ñèìïàòè÷íûé notebook è âîçâðàòèì ïðîöåäóðó ñîçäàíèÿ íîâûõ ñòðàíèö â í¸ì
startNotebook dialog = do
upbox <- dialogGetUpper dialog
nb <- notebookNew; boxPackStart upbox nb PackGrow 0
let newPage name = do hbox <- hBoxNew False 0; notebookAppendPage nb hbox =<< i18n name
vbox <- vBoxNew False 0; boxPackStart hbox vbox PackGrow 5
return vbox
return (nb,newPage)
-- |Âûïîëíèòü îïåðàöèþ ñ èñïîëüçîâàíèåì âðåìåííîãî ôàéëà
withTempFile contents action = do
tempDir <- getTempDir
createDirectoryHierarchy tempDir
fix $ \go -> do n <- generateRandomBytes 4 >>== encode16
let tempname = tempDir </> ("freearc"++n++".tmp")
e <- fileExist tempname
if e then go
else do filePutBinary tempname contents
ensureCtrlBreak "fileRemove tempfile" (ignoreErrors$ fileRemove tempname) $ do
action tempname