-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailRuCloud.dpr
1874 lines (1673 loc) · 74.4 KB
/
MailRuCloud.dpr
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
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
library MailRuCloud;
uses
SysUtils, System.Generics.Collections, DateUtils, windows, Classes, PLUGIN_TYPES, IdSSLOpenSSLHeaders, messages, inifiles, Vcl.controls, CloudMailRu in 'CloudMailRu.pas', MRC_Helper in 'MRC_Helper.pas', Accounts in 'Accounts.pas'{AccountsForm}, RemoteProperty in 'RemoteProperty.pas'{PropertyForm}, Descriptions in 'Descriptions.pas', ConnectionManager in 'ConnectionManager.pas', Settings in 'Settings.pas', ANSIFunctions in 'ANSIFunctions.pas', DeletedProperty in 'DeletedProperty.pas'{DeletedPropertyForm}, InviteProperty in 'InviteProperty.pas'{InvitePropertyForm}, AskPassword, CMLJSON in 'CMLJSON.pas', CMLTypes in 'CMLTypes.pas', DCPbase64 in 'DCPCrypt\DCPbase64.pas', DCPblockciphers in 'DCPCrypt\DCPblockciphers.pas', DCPconst in 'DCPCrypt\DCPconst.pas',
DCPcrypt2 in 'DCPCrypt\DCPcrypt2.pas', DCPreg in 'DCPCrypt\DCPreg.pas', DCPtypes in 'DCPCrypt\DCPtypes.pas', DCPblowfish in 'DCPCrypt\Ciphers\DCPblowfish.pas', DCPcast128 in 'DCPCrypt\Ciphers\DCPcast128.pas', DCPcast256 in 'DCPCrypt\Ciphers\DCPcast256.pas', DCPdes in 'DCPCrypt\Ciphers\DCPdes.pas', DCPgost in 'DCPCrypt\Ciphers\DCPgost.pas', DCPice in 'DCPCrypt\Ciphers\DCPice.pas', DCPidea in 'DCPCrypt\Ciphers\DCPidea.pas', DCPmars in 'DCPCrypt\Ciphers\DCPmars.pas', DCPmisty1 in 'DCPCrypt\Ciphers\DCPmisty1.pas', DCPrc2 in 'DCPCrypt\Ciphers\DCPrc2.pas', DCPrc4 in 'DCPCrypt\Ciphers\DCPrc4.pas', DCPrc5 in 'DCPCrypt\Ciphers\DCPrc5.pas', DCPrc6 in 'DCPCrypt\Ciphers\DCPrc6.pas', DCPrijndael in 'DCPCrypt\Ciphers\DCPrijndael.pas', DCPserpent in 'DCPCrypt\Ciphers\DCPserpent.pas',
DCPtea in 'DCPCrypt\Ciphers\DCPtea.pas', DCPtwofish in 'DCPCrypt\Ciphers\DCPtwofish.pas', DCPhaval in 'DCPCrypt\Hashes\DCPhaval.pas', DCPmd4 in 'DCPCrypt\Hashes\DCPmd4.pas', DCPmd5 in 'DCPCrypt\Hashes\DCPmd5.pas', DCPripemd128 in 'DCPCrypt\Hashes\DCPripemd128.pas', DCPripemd160 in 'DCPCrypt\Hashes\DCPripemd160.pas', DCPsha1 in 'DCPCrypt\Hashes\DCPsha1.pas', DCPsha256 in 'DCPCrypt\Hashes\DCPsha256.pas', DCPsha512 in 'DCPCrypt\Hashes\DCPsha512.pas', DCPtiger in 'DCPCrypt\Hashes\DCPtiger.pas', TCPasswordManagerHelper in 'TCPasswordManagerHelper.pas';
{$IFDEF WIN64}
{$E wfx64}
{$ENDIF}
{$IFDEF WIN32}
{$E wfx}
{$ENDIF}
{$R *.dres}
{$R *.res}
const
{$IFDEF WIN64}
PlatformDllPath = 'x64';
{$ENDIF}
{$IFDEF WIN32}
PlatformDllPath = 'x32';
{$ENDIF}
var
AccountsIniFilePath: WideString;
SettingsIniFilePath: WideString;
GlobalPath, PluginPath, AppDataDir, IniDir: WideString;
AccountsList: TStringList; //Global accounts list
FileCounter: integer = 0;
CurrentlyMovedDir: TRealPath;
ThreadSkipListDelete: TDictionary<DWORD, Boolean>; //Массив id потоков, для которых операции получения листинга должны быть пропущены (при удалении)
ThreadSkipListRenMov: TDictionary<DWORD, Boolean>; //Массив id потоков, для которых операции получения листинга должны быть пропущены (при копировании/перемещении)
ThreadCanAbortRenMov: TDictionary<DWORD, Boolean>; //Массив id потоков, для которых в операциях получения листинга должен быть выведен дополнительный диалог прогресса с возможностью отмены операции (fix issue #113)
ThreadListingAborted: TDictionary<DWORD, Boolean>; //Массив id потоков, для которых в операциях получения листинга была нажата отмена
ThreadRetryCountDownload: TDictionary<DWORD, Int32>; //массив [id потока => количество попыток] для подсчёта количества повторов скачивания файла
ThreadRetryCountUpload: TDictionary<DWORD, Int32>; //массив [id потока => количество попыток] для подсчёта количества повторов закачивания файла
ThreadRetryCountRenMov: TDictionary<DWORD, Int32>; //массив [id потока => количество попыток] для подсчёта количества повторов межсерверных операций с файлом
ThreadBackgroundJobs: TDictionary<WideString, Int32>; //массив [account root => количество потоков] для хранения количества текущих фоновых задач (предохраняемся от удаления объектов, которые могут быть использованы потоками)
ThreadBackgroundThreads: TDictionary<DWORD, Int32>; //массив [id потока => статус операции] для хранения текущих фоновых потоков (предохраняемся от завершения работы плагина при закрытии TC)
ThreadFsStatusInfo: TDictionary<DWORD, Int32>; //массив [id потока => текущая операция] для хранения контекста выполняемой операции (применяем для отлова перемещений каталогов)
ThreadFsRemoveDirSkippedPath: TDictionary<Int32, TStringList>; //массив [id потока => путь] для хранения путей, пропускаемых при перемещении (см. issue #168).
{Callback data}
PluginNum: integer;
MyProgressProc: TProgressProcW;
MyLogProc: TLogProcW;
MyRequestProc: TRequestProcW;
{Global stuff}
CurrentListing: TCloudMailRuDirListing;
CurrentIncomingInvitesListing: TCloudMailRuIncomingInviteInfoListing;
ConnectionManager: TConnectionManager;
CurrentDescriptions: TDescription;
ProxySettings: TProxySettings;
PasswordManager: TTCPasswordManager;
procedure LogHandle(LogLevel, MsgType: integer; LogString: PWideChar); stdcall;
begin
if (Assigned(MyLogProc)) and CheckFlag(LogLevel, GetPluginSettings(SettingsIniFilePath).LogLevel) then
MyLogProc(PluginNum, MsgType, LogString);
end;
function RequestHandle(RequestType: integer; CustomTitle, CustomText, ReturnedText: PWideChar; maxlen: integer): Bool; stdcall;
begin
Result := false;
if Assigned(MyRequestProc) then
Result := MyRequestProc(PluginNum, RequestType, CustomTitle, CustomText, ReturnedText, maxlen);
end;
function ProgressHandle(SourceName, TargetName: PWideChar; PercentDone: integer): integer; stdcall;
begin
Result := 0;
if Assigned(MyProgressProc) then
Result := MyProgressProc(PluginNum, SourceName, TargetName, PercentDone);
end;
function CloudMailRuDirListingItemToFindData(DirListing: TCloudMailRuDirListingItem; DirsAsSymlinks: Boolean = false): tWIN32FINDDATAW;
begin
if (DirListing.deleted_from <> '') then //items inside trash bin
begin
Result.ftCreationTime := DateTimeToFileTime(UnixToDateTime(DirListing.deleted_at, false));
Result.ftLastWriteTime := Result.ftCreationTime;
if (DirListing.type_ = TYPE_DIR) then
Result.dwFileAttributes := FILE_ATTRIBUTE_DIRECTORY
else
Result.dwFileAttributes := 0;
end else if (DirListing.type_ = TYPE_DIR) or (DirListing.kind = KIND_SHARED) then
begin
Result.ftCreationTime.dwLowDateTime := 0;
Result.ftCreationTime.dwHighDateTime := 0;
Result.ftLastWriteTime.dwHighDateTime := 0;
Result.ftLastWriteTime.dwLowDateTime := 0;
if DirsAsSymlinks then
Result.dwFileAttributes := 0
else
Result.dwFileAttributes := FILE_ATTRIBUTE_DIRECTORY;
end else begin
Result.ftCreationTime := DateTimeToFileTime(UnixToDateTime(DirListing.mtime, false));
Result.ftLastWriteTime := Result.ftCreationTime;
Result.dwFileAttributes := 0;
end;
if (DirListing.size > MAXDWORD) then
Result.nFileSizeHigh := DirListing.size div MAXDWORD
else
Result.nFileSizeHigh := 0;
Result.nFileSizeLow := DirListing.size;
strpcopy(Result.cFileName, DirListing.name);
end;
function FindData_emptyDir(DirName: WideString = '.'): tWIN32FINDDATAW;
begin
strpcopy(Result.cFileName, DirName);
Result.ftCreationTime.dwLowDateTime := 0;
Result.ftCreationTime.dwHighDateTime := 0;
Result.ftLastWriteTime.dwHighDateTime := 0;
Result.ftLastWriteTime.dwLowDateTime := 0;
Result.nFileSizeHigh := 0;
Result.nFileSizeLow := 0;
Result.dwFileAttributes := FILE_ATTRIBUTE_DIRECTORY;
end;
function FindListingItemByName(DirListing: TCloudMailRuDirListing; ItemName: WideString): TCloudMailRuDirListingItem;
var
CurrentItem: TCloudMailRuDirListingItem;
begin
for CurrentItem in DirListing do
if CurrentItem.name = ItemName then
exit(CurrentItem);
end;
function FindListingItemByHomePath(DirListing: TCloudMailRuDirListing; HomePath: WideString): TCloudMailRuDirListingItem;
var
CurrentItem: TCloudMailRuDirListingItem;
begin
HomePath := '/' + StringReplace(HomePath, WideString('\'), WideString('/'), [rfReplaceAll, rfIgnoreCase]);
for CurrentItem in DirListing do
if CurrentItem.home = HomePath then
exit(CurrentItem);
end;
{Пытаемся найти объект в облаке по его пути, сначала в текущем списке, если нет - то ищем в облаке}
function FindListingItemByPath(CurrentListing: TCloudMailRuDirListing; path: TRealPath; UpdateListing: Boolean = true): TCloudMailRuDirListingItem;
var
getResult: integer;
CurrentCloud: TCloudMailRu;
begin
if path.trashDir or path.sharedDir{or path.invitesDir} then
Result := FindListingItemByName(CurrentListing, path.path)//Виртуальные каталоги не возвращают HomePath
else
Result := FindListingItemByHomePath(CurrentListing, path.path); //сначала попробуем найти поле в имеющемся списке
if (Result.name = '') and UpdateListing then //если там его нет (нажали пробел на папке, например), то запросим в облаке напрямую, в зависимости от того, внутри чего мы находимся
begin
CurrentCloud := ConnectionManager.get(path.account, getResult);
if not Assigned(CurrentCloud) then
exit;
if path.trashDir then //корзина - обновим CurrentListing, поищем в нём
begin
if CurrentCloud.getTrashbinListing(CurrentListing) then
exit(FindListingItemByName(CurrentListing, path.path));
end;
if path.sharedDir then //ссылки - обновим список
begin
if CurrentCloud.getSharedLinksListing(CurrentListing) then
exit(FindListingItemByName(CurrentListing, path.path));
end;
if path.invitesDir then
begin
//FindIncomingInviteItemByPath in that case!
end;
if CurrentCloud.statusFile(path.path, Result) then //Обычный каталог
begin
if (Result.home = '') and not CurrentCloud.isPublicShare then
LogHandle(LogLevelError, MSGTYPE_IMPORTANTERROR, PWideChar('Cant find file ' + path.path)); {Такого быть не может, но...}
end;
end; //Не рапортуем, это будет уровнем выше
end;
function FindIncomingInviteItemByPath(InviteListing: TCloudMailRuIncomingInviteInfoListing; path: TRealPath): TCloudMailRuIncomingInviteInfo;
var
getResult: integer;
function FindListingItemByName(InviteListing: TCloudMailRuIncomingInviteInfoListing; ItemName: WideString): TCloudMailRuIncomingInviteInfo;
var
CurrentItem: TCloudMailRuIncomingInviteInfo;
begin
for CurrentItem in InviteListing do
if CurrentItem.name = ItemName then
exit(CurrentItem);
end;
begin
Result := FindListingItemByName(InviteListing, path.path);
{item not found in current global listing, so refresh it}
if Result.name = '' then
if ConnectionManager.get(path.account, getResult).getIncomingLinksListing(CurrentIncomingInvitesListing) then
exit(FindListingItemByName(CurrentIncomingInvitesListing, path.path));
end;
function DeleteLocalFile(LocalName: WideString): integer;
var
UNCLocalName: WideString;
DeleteFailOnUploadMode, DeleteFailOnUploadModeAsked: integer;
begin
Result := FS_FILE_OK;
DeleteFailOnUploadModeAsked := IDRETRY;
UNCLocalName := GetUNCFilePath(LocalName);
while (not DeleteFileW(PWideChar(UNCLocalName))) and (DeleteFailOnUploadModeAsked = IDRETRY) do
begin
DeleteFailOnUploadMode := GetPluginSettings(SettingsIniFilePath).DeleteFailOnUploadMode;
if DeleteFailOnUploadMode = DeleteFailOnUploadAsk then
begin
DeleteFailOnUploadModeAsked := messagebox(FindTCWindow, PWideChar('Can''t delete file ' + LocalName + '. Continue operation?'), 'File deletion error', MB_ABORTRETRYIGNORE + MB_ICONQUESTION);
case DeleteFailOnUploadModeAsked of
IDRETRY:
continue;
IDABORT:
DeleteFailOnUploadMode := DeleteFailOnUploadAbort;
IDIGNORE:
DeleteFailOnUploadMode := DeleteFailOnUploadIgnore;
end;
end;
case DeleteFailOnUploadMode of
DeleteFailOnUploadAbort:
begin
LogHandle(LogLevelDetail, MSGTYPE_IMPORTANTERROR, PWideChar('Can''t delete file ' + LocalName + ', aborted'));
exit(FS_FILE_NOTSUPPORTED);
end;
DeleteFailOnUploadDeleteIgnore, DeleteFailOnUploadDeleteAbort:
begin
//check if file just have RO attr, then remove it. If user has lack of rights, then ignore or abort
if ((FileGetAttr(UNCLocalName) or faReadOnly) <> 0) and ((FileSetAttr(UNCLocalName, not faReadOnly) = 0) and (DeleteFileW(PWideChar(UNCLocalName)))) then
begin
LogHandle(LogLevelDetail, MSGTYPE_IMPORTANTERROR, PWideChar('Read only file ' + LocalName + ' deleted'));
exit(FS_FILE_OK);
end else begin
if GetPluginSettings(SettingsIniFilePath).DeleteFailOnUploadMode = DeleteFailOnUploadDeleteIgnore then
begin
LogHandle(LogLevelDetail, MSGTYPE_IMPORTANTERROR, PWideChar('Can''t delete file ' + LocalName + ', ignored'));
exit(FS_FILE_OK);
end else begin
LogHandle(LogLevelDetail, MSGTYPE_IMPORTANTERROR, PWideChar('Can''t delete file ' + LocalName + ', aborted'));
exit(FS_FILE_NOTSUPPORTED);
end;
end;
end;
else
begin
LogHandle(LogLevelDetail, MSGTYPE_IMPORTANTERROR, PWideChar('Can''t delete file ' + LocalName + ', ignored'));
end;
end;
end;
end;
function FsGetBackgroundFlags: integer; stdcall;
begin
if GetPluginSettings(SettingsIniFilePath).DisableMultiThreading then
Result := 0
else
Result := BG_DOWNLOAD + BG_UPLOAD; //+ BG_ASK_USER;
end;
function FsInit(PluginNr: integer; pProgressProc: TProgressProc; pLogProc: TLogProc; pRequestProc: TRequestProc): integer; stdcall;
begin
Result := 0;
end;
{GLORIOUS UNICODE MASTER RACE}
function FsInitW(PluginNr: integer; pProgressProc: TProgressProcW; pLogProc: TLogProcW; pRequestProc: TRequestProcW): integer; stdcall; //Вход в плагин.
begin
PluginNum := PluginNr;
MyProgressProc := pProgressProc;
MyLogProc := pLogProc;
MyRequestProc := pRequestProc;
Result := 0;
CurrentDescriptions := TDescription.Create(GetTmpFileName('ion'), GetTCCommentPreferredFormat);
end;
procedure FsStatusInfoW(RemoteDir: PWideChar; InfoStartEnd, InfoOperation: integer); stdcall; //Начало и конец операций FS
var
RealPath: TRealPath;
getResult: integer;
BackgroundJobsCount: integer;
begin
RealPath := ExtractRealPath(RemoteDir);
if (InfoStartEnd = FS_STATUS_START) then
begin //todo: save operation info into thread-related dictionary, so we can determine it later
ThreadFsStatusInfo.AddOrSetValue(GetCurrentThreadID(), InfoOperation);
case InfoOperation of
FS_STATUS_OP_LIST:
begin
if (GetPluginSettings(SettingsIniFilePath).DescriptionEnabled) and inAccount(RealPath) then
begin
if ConnectionManager.get(RealPath.account, getResult).getDescriptionFile(IncludeTrailingBackslash(RealPath.path) + GetDescriptionFileName(SettingsIniFilePath), CurrentDescriptions.ionFilename) then
begin
CurrentDescriptions.Read;
end else begin
CurrentDescriptions.Clear;
end;
end;
end;
FS_STATUS_OP_GET_SINGLE:
begin
ThreadRetryCountDownload.AddOrSetValue(GetCurrentThreadID(), 0);
end;
FS_STATUS_OP_GET_MULTI:
begin
ThreadRetryCountDownload.AddOrSetValue(GetCurrentThreadID(), 0);
end;
FS_STATUS_OP_PUT_SINGLE:
begin
ThreadRetryCountUpload.AddOrSetValue(GetCurrentThreadID(), 0);
end;
FS_STATUS_OP_PUT_MULTI:
begin
ThreadRetryCountUpload.AddOrSetValue(GetCurrentThreadID(), 0);
end;
FS_STATUS_OP_RENMOV_SINGLE:
begin
end;
FS_STATUS_OP_RENMOV_MULTI:
begin
if ConnectionManager.get(RealPath.account, getResult).isPublicShare then
begin
LogHandle(LogLevelWarning, MSGTYPE_IMPORTANTERROR, PWideChar('Direct copying from public accounts not supported'));
ThreadSkipListRenMov.AddOrSetValue(GetCurrentThreadID, true);
end;
ThreadRetryCountRenMov.AddOrSetValue(GetCurrentThreadID(), 0);
ThreadCanAbortRenMov.AddOrSetValue(GetCurrentThreadID, true);
ThreadFsRemoveDirSkippedPath.AddOrSetValue(GetCurrentThreadID, TStringList.Create());
end;
FS_STATUS_OP_DELETE:
begin
//ThreadSkipListDelete.Add(GetCurrentThreadID());
ThreadSkipListDelete.AddOrSetValue(GetCurrentThreadID, true);
end;
FS_STATUS_OP_ATTRIB:
begin
end;
FS_STATUS_OP_MKDIR:
begin
end;
FS_STATUS_OP_EXEC:
begin
end;
FS_STATUS_OP_CALCSIZE:
begin
end;
FS_STATUS_OP_SEARCH:
begin
end;
FS_STATUS_OP_SEARCH_TEXT:
begin
end;
FS_STATUS_OP_SYNC_SEARCH:
begin
end;
FS_STATUS_OP_SYNC_GET:
begin
end;
FS_STATUS_OP_SYNC_PUT:
begin
end;
FS_STATUS_OP_SYNC_DELETE:
begin
end;
FS_STATUS_OP_GET_MULTI_THREAD:
begin
ThreadRetryCountDownload.AddOrSetValue(GetCurrentThreadID(), 0);
if not ThreadBackgroundJobs.TryGetValue(RealPath.account, BackgroundJobsCount) then
BackgroundJobsCount := 0;
ThreadBackgroundJobs.AddOrSetValue(RealPath.account, BackgroundJobsCount + 1);
ThreadBackgroundThreads.AddOrSetValue(GetCurrentThreadID(), FS_STATUS_OP_GET_MULTI_THREAD);
end;
FS_STATUS_OP_PUT_MULTI_THREAD:
begin
ThreadRetryCountUpload.AddOrSetValue(GetCurrentThreadID(), 0);
if not ThreadBackgroundJobs.TryGetValue(RealPath.account, BackgroundJobsCount) then
BackgroundJobsCount := 0;
ThreadBackgroundJobs.AddOrSetValue(RealPath.account, BackgroundJobsCount + 1);
ThreadBackgroundThreads.AddOrSetValue(GetCurrentThreadID(), FS_STATUS_OP_PUT_MULTI_THREAD);
end;
end;
exit;
end;
if (InfoStartEnd = FS_STATUS_END) then
begin
ThreadFsStatusInfo.Remove(GetCurrentThreadID);
case InfoOperation of
FS_STATUS_OP_LIST:
begin
end;
FS_STATUS_OP_GET_SINGLE:
begin
end;
FS_STATUS_OP_GET_MULTI:
begin
end;
FS_STATUS_OP_PUT_SINGLE:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_PUT_MULTI:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_RENMOV_SINGLE:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_RENMOV_MULTI:
begin
ThreadSkipListRenMov.AddOrSetValue(GetCurrentThreadID, false);
ThreadCanAbortRenMov.AddOrSetValue(GetCurrentThreadID, false);
ThreadFsRemoveDirSkippedPath.Items[GetCurrentThreadID].Free;
ThreadFsRemoveDirSkippedPath.AddOrSetValue(GetCurrentThreadID, nil);
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_DELETE:
begin
ThreadSkipListDelete.AddOrSetValue(GetCurrentThreadID(), false);
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_ATTRIB:
begin
end;
FS_STATUS_OP_MKDIR:
begin
end;
FS_STATUS_OP_EXEC:
begin
end;
FS_STATUS_OP_CALCSIZE:
begin
end;
FS_STATUS_OP_SEARCH:
begin
end;
FS_STATUS_OP_SEARCH_TEXT:
begin
end;
FS_STATUS_OP_SYNC_SEARCH:
begin
end;
FS_STATUS_OP_SYNC_GET:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_SYNC_PUT:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_SYNC_DELETE:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
end;
FS_STATUS_OP_GET_MULTI_THREAD:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
if not ThreadBackgroundJobs.TryGetValue(RealPath.account, BackgroundJobsCount) then
BackgroundJobsCount := 0;
ThreadBackgroundJobs.AddOrSetValue(RealPath.account, BackgroundJobsCount - 1);
ThreadBackgroundThreads.Remove(GetCurrentThreadID());
end;
FS_STATUS_OP_PUT_MULTI_THREAD:
begin
if inAccount(RealPath) and GetPluginSettings(SettingsIniFilePath).LogUserSpace then
ConnectionManager.get(RealPath.account, getResult).logUserSpaceInfo;
if not ThreadBackgroundJobs.TryGetValue(RealPath.account, BackgroundJobsCount) then
BackgroundJobsCount := 0;
ThreadBackgroundJobs.AddOrSetValue(RealPath.account, BackgroundJobsCount - 1);
ThreadBackgroundThreads.Remove(GetCurrentThreadID());
end;
end;
exit;
end;
end;
function FsFindFirstW(path: PWideChar; var FindData: tWIN32FINDDATAW): THandle; stdcall;
var //Получение первого файла в папке. Result тоталом не используется (можно использовать для работы плагина).
RealPath: TRealPath;
getResult: integer;
SkipListDelete, SkipListRenMov, CanAbortRenMov, RenMovAborted: Boolean;
CurrentItem: TCloudMailRuDirListingItem;
CurrentCloud: TCloudMailRu;
begin
ThreadSkipListDelete.TryGetValue(GetCurrentThreadID(), SkipListDelete);
ThreadSkipListRenMov.TryGetValue(GetCurrentThreadID(), SkipListRenMov);
ThreadCanAbortRenMov.TryGetValue(GetCurrentThreadID(), CanAbortRenMov);
if (CanAbortRenMov and (ProgressHandle(path, nil, 0) = 1)) then
begin
ThreadListingAborted.AddOrSetValue(GetCurrentThreadID(), true);
RenMovAborted := true;
end
else
RenMovAborted := false;
if SkipListDelete or SkipListRenMov or RenMovAborted then
begin
SetLastError(ERROR_NO_MORE_FILES);
exit(INVALID_HANDLE_VALUE);
end;
//Result := FIND_NO_MORE_FILES;
GlobalPath := path;
if GlobalPath = '\' then
begin //список соединений
AccountsList := TStringList.Create;
GetAccountsListFromIniFile(AccountsIniFilePath, AccountsList);
if (AccountsList.Count > 0) then
begin
AddVirtualAccountsToAccountsList(AccountsIniFilePath, AccountsList, [GetPluginSettings(SettingsIniFilePath).ShowTrashFolders, GetPluginSettings(SettingsIniFilePath).ShowSharedFolders, GetPluginSettings(SettingsIniFilePath).ShowInvitesFolders]);
FindData := FindData_emptyDir(AccountsList.Strings[0]);
FileCounter := 1;
Result := FIND_ROOT_DIRECTORY;
end else begin
Result := INVALID_HANDLE_VALUE; //Нельзя использовать exit
SetLastError(ERROR_NO_MORE_FILES);
end;
end else begin
RealPath := ExtractRealPath(GlobalPath);
CurrentCloud := ConnectionManager.get(RealPath.account, getResult);
if getResult <> CLOUD_OPERATION_OK then
begin
SetLastError(ERROR_ACCESS_DENIED);
exit(INVALID_HANDLE_VALUE);
end;
if not Assigned(CurrentCloud) then
begin
SetLastError(ERROR_PATH_NOT_FOUND);
exit(INVALID_HANDLE_VALUE);
end;
if RealPath.trashDir then
begin
if not CurrentCloud.getTrashbinListing(CurrentListing) then
SetLastError(ERROR_PATH_NOT_FOUND);
end else if RealPath.sharedDir then
begin
if not CurrentCloud.getSharedLinksListing(CurrentListing) then
SetLastError(ERROR_PATH_NOT_FOUND); //that will be interpreted as symlinks later
end else if RealPath.invitesDir then
begin
if not CurrentCloud.getIncomingLinksListing(CurrentListing, CurrentIncomingInvitesListing) then
SetLastError(ERROR_PATH_NOT_FOUND); //одновременно получаем оба листинга, чтобы не перечитывать листинг инватов на каждый чих
end else begin //Нужно проверить, является ли открываемый объект каталогом - для файлов API вернёт листинг вышестоящего каталога, см. issue #174
if not CurrentCloud.getDirListing(RealPath.path, CurrentListing) then
SetLastError(ERROR_PATH_NOT_FOUND);
end;
if (RealPath.invitesDir or RealPath.trashDir or RealPath.sharedDir) and (RealPath.path <> '') then //игнорим попытки получить листинги объектов вирутальных каталогов
begin
SetLastError(ERROR_ACCESS_DENIED);
exit(INVALID_HANDLE_VALUE);
end;
if CurrentCloud.isPublicShare then
CurrentItem := FindListingItemByName(CurrentListing, ExtractUniversalFileName(RealPath.path))
else
CurrentItem := FindListingItemByHomePath(CurrentListing, RealPath.path);
if (CurrentItem.name <> '') and (CurrentItem.type_ <> TYPE_DIR) then
begin
SetLastError(ERROR_PATH_NOT_FOUND);
exit(INVALID_HANDLE_VALUE);
end;
if (Length(CurrentListing) = 0) then
begin
FindData := FindData_emptyDir(); //воркароунд бага с невозможностью входа в пустой каталог, см. http://www.ghisler.ch/board/viewtopic.php?t=42399
Result := FIND_NO_MORE_FILES;
SetLastError(ERROR_NO_MORE_FILES);
end else begin
FindData := CloudMailRuDirListingItemToFindData(CurrentListing[0], RealPath.sharedDir); //folders inside shared links directory must be displayed as symlinks
FileCounter := 1;
if RealPath.sharedDir then
Result := FIND_SHARED_LINKS
else
Result := FIND_OK;
end;
end;
end;
function FsFindNextW(Hdl: THandle; var FindData: tWIN32FINDDATAW): Bool; stdcall;
begin
if GlobalPath = '\' then
begin
if (AccountsList.Count > FileCounter) then
begin
FindData := FindData_emptyDir(AccountsList.Strings[FileCounter]);
inc(FileCounter);
Result := true;
end
else
Result := false;
end else begin
//Получение последующих файлов в папке (вызывается до тех пор, пока не вернёт false).
if (Length(CurrentListing) > FileCounter) then
begin
FindData := CloudMailRuDirListingItemToFindData(CurrentListing[FileCounter], Hdl = FIND_SHARED_LINKS);
Result := true;
inc(FileCounter);
end else begin
FillChar(FindData, SizeOf(WIN32_FIND_DATA), 0);
FileCounter := 0;
Result := false;
end;
end;
end;
function FsFindClose(Hdl: THandle): integer; stdcall;
begin //Завершение получения списка файлов. Result тоталом не используется (всегда равен 0)
//SetLength(CurrentListing, 0); // Пусть будет
if Hdl = FIND_ROOT_DIRECTORY then
FreeAndNil(AccountsList);
Result := 0;
FileCounter := 0;
end;
function ExecTrashbinProperties(MainWin: THandle; RealPath: TRealPath): integer;
var
Cloud: TCloudMailRu;
getResult: integer;
CurrentItem: TCloudMailRuDirListingItem;
begin
Result := FS_EXEC_OK;
Cloud := ConnectionManager.get(RealPath.account, getResult);
if RealPath.path = '' then //main trashbin folder properties
begin
if not Cloud.getTrashbinListing(CurrentListing) then
exit(FS_EXEC_ERROR);
getResult := TDeletedPropertyForm.ShowProperties(MainWin, CurrentListing, true, RealPath.account);
end else begin //one item in trashbin
CurrentItem := FindListingItemByPath(CurrentListing, RealPath); //для одинаково именованных файлов в корзине будут показываться свойства первого, сорян
getResult := TDeletedPropertyForm.ShowProperties(MainWin, [CurrentItem]);
end;
case (getResult) of
mrNo:
if not Cloud.trashbinEmpty then
exit(FS_EXEC_ERROR);
mrYes:
if not Cloud.trashbinRestore(CurrentItem.deleted_from + CurrentItem.name, CurrentItem.rev) then
exit(FS_EXEC_ERROR);
mrYesToAll:
for CurrentItem in CurrentListing do
if not Cloud.trashbinRestore(CurrentItem.deleted_from + CurrentItem.name, CurrentItem.rev) then
exit(FS_EXEC_ERROR);
end;
PostMessage(MainWin, WM_USER + 51, 540, 0); //TC does not update current panel, so we should do it this way
end;
function ExecSharedAction(MainWin: THandle; RealPath: TRealPath; RemoteName: PWideChar; ActionOpen: Boolean = true): integer;
var
Cloud: TCloudMailRu;
CurrentItem: TCloudMailRuDirListingItem;
getResult: integer;
begin
Result := FS_EXEC_OK;
if ActionOpen then //open item, i.e. treat it as symlink to original location
begin
CurrentItem := FindListingItemByPath(CurrentListing, RealPath);
if CurrentItem.type_ = TYPE_FILE then
strpcopy(RemoteName, '\' + RealPath.account + ExtractFilePath(UrlToPath(CurrentItem.home)))
else
strpcopy(RemoteName, '\' + RealPath.account + UrlToPath(CurrentItem.home));
Result := FS_EXEC_SYMLINK;
end else begin
if RealPath.path = '' then
TAccountsForm.ShowAccounts(MainWin, AccountsIniFilePath, SettingsIniFilePath, PasswordManager, RealPath.account)//main shared folder properties - open connection settings
else
begin
Cloud := ConnectionManager.get(RealPath.account, getResult);
CurrentItem := FindListingItemByPath(CurrentListing, RealPath);
if Cloud.statusFile(CurrentItem.home, CurrentItem) then
TPropertyForm.ShowProperty(MainWin, RealPath.path, CurrentItem, Cloud, GetPluginSettings(SettingsIniFilePath).DownloadLinksEncode, GetPluginSettings(SettingsIniFilePath).AutoUpdateDownloadListing, false, false, GetDescriptionFileName(SettingsIniFilePath))
end;
end;
end;
function ExecInvitesAction(MainWin: THandle; RealPath: TRealPath): integer;
var
Cloud: TCloudMailRu;
getResult: integer;
CurrentInvite: TCloudMailRuIncomingInviteInfo;
begin
Result := FS_EXEC_OK;
Cloud := ConnectionManager.get(RealPath.account, getResult);
if RealPath.path = '' then //main invites folder properties
begin
TAccountsForm.ShowAccounts(MainWin, AccountsIniFilePath, SettingsIniFilePath, PasswordManager, RealPath.account)
end else begin //one invite item
CurrentInvite := FindIncomingInviteItemByPath(CurrentIncomingInvitesListing, RealPath);
if CurrentInvite.name = '' then
exit(FS_EXEC_ERROR);
getResult := TInvitePropertyForm.ShowProperties(MainWin, CurrentInvite);
end;
case (getResult) of
mrAbort:
Cloud.unmountFolder(CurrentInvite.name, true);
mrClose:
Cloud.unmountFolder(CurrentInvite.name, false);
mrYes:
Cloud.mountFolder(CurrentInvite.name, CurrentInvite.invite_token);
mrNo:
Cloud.rejectInvite(CurrentInvite.invite_token);
end;
PostMessage(MainWin, WM_USER + 51, 540, 0); //TC does not update current panel, so we should do it this way
end;
function ExecProperties(MainWin: THandle; RealPath: TRealPath): integer;
var
Cloud: TCloudMailRu;
CurrentItem: TCloudMailRuDirListingItem;
getResult: integer;
begin
Result := FS_EXEC_OK;
if RealPath.path = '' then
TAccountsForm.ShowAccounts(MainWin, AccountsIniFilePath, SettingsIniFilePath, PasswordManager, RealPath.account)//show account properties
else
begin
Cloud := ConnectionManager.get(RealPath.account, getResult);
//всегда нужно обновлять статус на сервере, CurrentListing может быть изменён в другой панели
if (Cloud.statusFile(RealPath.path, CurrentItem)) and (idContinue = TPropertyForm.ShowProperty(MainWin, RealPath.path, CurrentItem, Cloud, GetPluginSettings(SettingsIniFilePath).DownloadLinksEncode, GetPluginSettings(SettingsIniFilePath).AutoUpdateDownloadListing, GetPluginSettings(SettingsIniFilePath).DescriptionEnabled, GetPluginSettings(SettingsIniFilePath).DescriptionEditorEnabled, GetDescriptionFileName(SettingsIniFilePath))) then
PostMessage(MainWin, WM_USER + 51, 540, 0); //refresh tc panel if description edited
end;
end;
function ExecCommand(RemoteName: PWideChar; command: WideString; Parameter: WideString = ''): integer;
var
RealPath: TRealPath;
getResult: integer;
Cloud: TCloudMailRu;
begin
Result := FS_EXEC_OK;
if command = 'rmdir' then
begin
RealPath := ExtractRealPath(RemoteName + Parameter);
if (ConnectionManager.get(RealPath.account, getResult).removeDir(RealPath.path) <> true) then
exit(FS_EXEC_ERROR);
end;
RealPath := ExtractRealPath(RemoteName); //default
Cloud := ConnectionManager.get(RealPath.account, getResult);
//undocumented, share current folder to email param
if command = 'share' then
if not(Cloud.shareFolder(RealPath.path, ExtractLinkFromUrl(Parameter), CLOUD_SHARE_RW)) then
exit(FS_EXEC_ERROR);
if command = 'clone' then
begin
if (Cloud.cloneWeblink(RealPath.path, ExtractLinkFromUrl(Parameter)) = CLOUD_OPERATION_OK) then
if GetPluginSettings(SettingsIniFilePath).LogUserSpace then
Cloud.logUserSpaceInfo
else
exit(FS_EXEC_ERROR);
end;
if command = 'trash' then //go to current account trash directory
begin
if Cloud.isPublicShare then
exit(FS_EXEC_ERROR);
if inAccount(RealPath, false) then
begin
strpcopy(RemoteName, '\' + RealPath.account + TrashPostfix);
exit(FS_EXEC_SYMLINK);
end;
end;
if command = 'shared' then
begin
if Cloud.isPublicShare then
exit(FS_EXEC_ERROR);
if inAccount(RealPath, false) then
begin
strpcopy(RemoteName, '\' + RealPath.account + SharedPostfix);
exit(FS_EXEC_SYMLINK);
end;
end;
if command = 'invites' then
begin
if Cloud.isPublicShare then
exit(FS_EXEC_ERROR);
if inAccount(RealPath, false) then
begin
strpcopy(RemoteName, '\' + RealPath.account + InvitesPostfix);
exit(FS_EXEC_SYMLINK);
end;
end;
end;
function FsExecuteFileW(MainWin: THandle; RemoteName, Verb: PWideChar): integer; stdcall; //Запуск файла
var
RealPath: TRealPath;
begin
RealPath := ExtractRealPath(RemoteName);
Result := FS_EXEC_OK;
if RealPath.upDirItem then
RealPath.path := ExtractFilePath(RealPath.path); //if somepath/.. item properties called
if RealPath.trashDir and ((Verb = 'open') or (Verb = 'properties')) then
exit(ExecTrashbinProperties(MainWin, RealPath));
if RealPath.sharedDir then
exit(ExecSharedAction(MainWin, RealPath, RemoteName, Verb = 'open'));
if RealPath.invitesDir then
exit(ExecInvitesAction(MainWin, RealPath));
if Verb = 'properties' then
exit(ExecProperties(MainWin, RealPath));
if Verb = 'open' then
exit(FS_EXEC_YOURSELF);
if copy(Verb, 1, 5) = 'quote' then
exit(ExecCommand(RemoteName, LowerCase(GetWord(Verb, 1)), GetWord(Verb, 2)));
//if copy(Verb, 1, 5) = 'chmod' then exit; //future usage
end;
procedure UpdateFileDescription(RemotePath: TRealPath; LocalFilePath: WideString; var Cloud: TCloudMailRu);
var
RemoteDescriptions, LocalDescriptions: TDescription;
RemoteIonPath, LocalTempPath: WideString;
RemoteIonExists: Boolean;
begin
RemoteIonPath := IncludeTrailingBackslash(ExtractFileDir(RemotePath.path)) + GetDescriptionFileName(SettingsIniFilePath);
LocalTempPath := GetTmpFileName('ion');
RemoteIonExists := Cloud.getDescriptionFile(RemoteIonPath, LocalTempPath);
if not RemoteIonExists then
exit; //удалённого файла описаний нет
RemoteDescriptions := TDescription.Create(LocalTempPath, GetTCCommentPreferredFormat);
RemoteDescriptions.Read;
LocalDescriptions := TDescription.Create(IncludeTrailingPathDelimiter(ExtractFileDir(LocalFilePath)) + GetDescriptionFileName(SettingsIniFilePath), GetTCCommentPreferredFormat); //open local ion file
LocalDescriptions.Read;
LocalDescriptions.CopyFrom(RemoteDescriptions, ExtractFileName(LocalFilePath));
LocalDescriptions.Write();
LocalDescriptions.Destroy;
RemoteDescriptions.Destroy
end;
procedure UpdateRemoteFileDescription(RemotePath: TRealPath; LocalFilePath: WideString; var Cloud: TCloudMailRu);
var
RemoteDescriptions, LocalDescriptions: TDescription;
RemoteIonPath, LocalIonPath, LocalTempPath: WideString;
RemoteIonExists: Boolean;
begin
RemoteIonPath := IncludeTrailingBackslash(ExtractFileDir(RemotePath.path)) + GetDescriptionFileName(SettingsIniFilePath);
LocalIonPath := IncludeTrailingBackslash(ExtractFileDir(LocalFilePath)) + GetDescriptionFileName(SettingsIniFilePath);
LocalTempPath := GetTmpFileName('ion');
if (not FileExists(LocalIonPath)) then
exit; //Файла описаний нет, не паримся
LocalDescriptions := TDescription.Create(LocalIonPath, GetTCCommentPreferredFormat);
LocalDescriptions.Read;
RemoteIonExists := Cloud.getDescriptionFile(RemoteIonPath, LocalTempPath);
RemoteDescriptions := TDescription.Create(LocalTempPath, GetTCCommentPreferredFormat);
if RemoteIonExists then
RemoteDescriptions.Read; //если был прежний файл - его надо перечитать
RemoteDescriptions.CopyFrom(LocalDescriptions, ExtractFileName(RemotePath.path));
RemoteDescriptions.Write();
if RemoteIonExists then
Cloud.deleteFile(RemoteIonPath); //Приходится удалять, потому что не знаем, как переписать
Cloud.putDesriptionFile(RemoteIonPath, RemoteDescriptions.ionFilename);
RemoteDescriptions.Destroy;
LocalDescriptions.Destroy;
end;
//Предполагается, что процедура происходит внутри одного облака - в плагине запрещены прямые операции между аккаунтами
procedure RenameRemoteFileDescription(OldRemotePath, NewRemotePath: TRealPath; var Cloud: TCloudMailRu);
var
OldDescriptions, NewDescriptions: TDescription;
OldRemoteIonPath, NewRemoteIonPath, OldLocalTempPath, NewLocalTempPath: WideString;
NewRemoteIonExists: Boolean;
OldItem, NewItem: WideString;
begin
OldItem := ExtractFileName(OldRemotePath.path);
NewItem := ExtractFileName(NewRemotePath.path);
OldRemoteIonPath := IncludeTrailingBackslash(ExtractFileDir(OldRemotePath.path)) + GetDescriptionFileName(SettingsIniFilePath);
NewRemoteIonPath := IncludeTrailingBackslash(ExtractFileDir(NewRemotePath.path)) + GetDescriptionFileName(SettingsIniFilePath);
OldLocalTempPath := GetTmpFileName('ion');
NewLocalTempPath := GetTmpFileName('ion');
if ExtractFileDir(OldRemotePath.path) = ExtractFileDir(NewRemotePath.path) then //переименование внутри одного файла
begin
if not Cloud.getDescriptionFile(OldRemoteIonPath, OldLocalTempPath) then
exit; //описания нет, переносить нечего
OldDescriptions := TDescription.Create(OldLocalTempPath, GetTCCommentPreferredFormat);
OldDescriptions.Read;
if (OldDescriptions.RenameItem(OldItem, NewItem)) then //метод сам проверит существование описания
begin
OldDescriptions.Write();
Cloud.deleteFile(OldRemoteIonPath);
Cloud.putDesriptionFile(OldRemoteIonPath, OldDescriptions.ionFilename);
end;
OldDescriptions.Destroy;
end
else //перенос и переименование в разных файлах (например, перемещение в подкаталог)
begin
if not Cloud.getDescriptionFile(OldRemoteIonPath, OldLocalTempPath) then
exit; //описания нет, не заморачиваемся
OldDescriptions := TDescription.Create(OldLocalTempPath, GetTCCommentPreferredFormat);
OldDescriptions.Read;
NewRemoteIonExists := Cloud.getDescriptionFile(NewRemoteIonPath, NewLocalTempPath);
NewDescriptions := TDescription.Create(NewLocalTempPath, GetTCCommentPreferredFormat);
if NewRemoteIonExists then
NewDescriptions.Read; //прочитать существующий, если его нет - то и читать нечего
NewDescriptions.SetValue(ExtractFileName(NewRemotePath.path), OldDescriptions.GetValue(ExtractFileName(OldRemotePath.path)));
OldDescriptions.DeleteValue(ExtractFileName(OldRemotePath.path));
OldDescriptions.Write();
NewDescriptions.Write();
Cloud.deleteFile(OldRemoteIonPath);
Cloud.putDesriptionFile(OldRemoteIonPath, OldDescriptions.ionFilename);
if NewRemoteIonExists then
Cloud.deleteFile(NewRemoteIonPath); //Если файл существовал ранее, его нужно удалить для последующей записи на его место
Cloud.putDesriptionFile(NewRemoteIonPath, NewDescriptions.ionFilename);
OldDescriptions.Destroy;
NewDescriptions.Destroy;
end;
end;
procedure DeleteRemoteFileDescription(RemotePath: TRealPath; var Cloud: TCloudMailRu);
var
RemoteDescriptions: TDescription;
RemoteIonPath, LocalTempPath: WideString;
begin
RemoteIonPath := IncludeTrailingBackslash(ExtractFileDir(RemotePath.path)) + GetDescriptionFileName(SettingsIniFilePath);
LocalTempPath := GetTmpFileName('ion');
if not Cloud.getDescriptionFile(RemoteIonPath, LocalTempPath) then
exit; //описания нет, не заморачиваемся
RemoteDescriptions := TDescription.Create(LocalTempPath, GetTCCommentPreferredFormat);
RemoteDescriptions.Read;
RemoteDescriptions.DeleteValue(ExtractFileName(RemotePath.path));
RemoteDescriptions.Write();
Cloud.deleteFile(RemoteIonPath); //Приходится удалять, потому что не знаем, как переписать
Cloud.putDesriptionFile(RemoteIonPath, RemoteDescriptions.ionFilename);
RemoteDescriptions.Destroy;
end;
function GetRemoteFile(RemotePath: TRealPath; LocalName, RemoteName: WideString; CopyFlags: integer): integer;
var
getResult: integer;
Item: TCloudMailRuDirListingItem;
Cloud: TCloudMailRu;
AccountSettings: TAccountSettings;
resultHash: WideString;
begin
resultHash := EmptyWideStr;
Cloud := ConnectionManager.get(RemotePath.account, getResult);
AccountSettings := GetAccountSettingsFromIniFile(AccountsIniFilePath, RemotePath.account);
Result := Cloud.getFile(WideString(RemotePath.path), LocalName, resultHash);