@@ -621,6 +621,41 @@ void SocketApi::command_DOWNLOAD_VIRTUAL_FILE(const QString &filesArg, SocketLis
621
621
}
622
622
}
623
623
624
+ /* Go over all the files ans replace them by a virtual file */
625
+ void SocketApi::command_REPLACE_VIRTUAL_FILE (const QString &filesArg, SocketListener *)
626
+ {
627
+ QStringList files = filesArg.split (QLatin1Char (' \x1e ' )); // Record Separator
628
+ auto suffix = QStringLiteral (APPLICATION_DOTVIRTUALFILE_SUFFIX);
629
+
630
+ for (const auto &file : files) {
631
+ QString relativePath;
632
+ auto folder = FolderMan::instance ()->folderForPath (file, &relativePath);
633
+ if (!folder)
634
+ continue ;
635
+ if (file.endsWith (suffix))
636
+ continue ;
637
+ QFileInfo fi (file);
638
+ if (fi.isDir ()) {
639
+ folder->journalDb ()->getFilesBelowPath (relativePath.toUtf8 (), [&](const SyncJournalFileRecord &rec) {
640
+ if (rec._type != ItemTypeFile || rec._path .endsWith (APPLICATION_DOTVIRTUALFILE_SUFFIX))
641
+ return ;
642
+ QString file = folder->path () + ' /' + QString::fromUtf8 (rec._path );
643
+ if (!FileSystem::rename (file, file + suffix)) {
644
+ qCWarning (lcSocketApi) << " Unable to rename " << file;
645
+ }
646
+ });
647
+ continue ;
648
+ }
649
+ SyncJournalFileRecord record;
650
+ if (!folder->journalDb ()->getFileRecord (relativePath, &record) || !record.isValid ())
651
+ continue ;
652
+ if (!FileSystem::rename (file, file + suffix)) {
653
+ qCWarning (lcSocketApi) << " Unable to rename " << file;
654
+ }
655
+ FolderMan::instance ()->scheduleFolder (folder);
656
+ }
657
+ }
658
+
624
659
void SocketApi::emailPrivateLink (const QString &link)
625
660
{
626
661
Utility::openEmailComposer (
@@ -763,12 +798,23 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
763
798
if (folder) {
764
799
auto virtualFileSuffix = QStringLiteral (APPLICATION_DOTVIRTUALFILE_SUFFIX);
765
800
bool hasVirtualFile = false ;
801
+ bool hasNormalFiles = false ;
802
+ bool hasDir = false ;
766
803
for (const auto &file : files) {
767
- if (file.endsWith (virtualFileSuffix) || (folder->useVirtualFiles () && QFileInfo (file).isDir ()))
804
+ if (QFileInfo (file).isDir ()) {
805
+ hasDir = true ;
806
+ } else if (file.endsWith (virtualFileSuffix)) {
768
807
hasVirtualFile = true ;
808
+ } else if (!hasNormalFiles) {
809
+ bool isOnTheServer = FileData::get (file).journalRecord ().isValid ();
810
+ hasNormalFiles = isOnTheServer;
811
+ }
769
812
}
770
- if (hasVirtualFile)
813
+ if (hasVirtualFile || (hasDir && folder-> useVirtualFiles ()) )
771
814
listener->sendMessage (QLatin1String (" MENU_ITEM:DOWNLOAD_VIRTUAL_FILE::" ) + tr (" Download file(s)" , " " , files.size ()));
815
+
816
+ if ((hasNormalFiles || hasDir) && folder->useVirtualFiles ())
817
+ listener->sendMessage (QLatin1String (" MENU_ITEM:REPLACE_VIRTUAL_FILE::" ) + tr (" Replace file(s) by virtual file" , " " , files.size ()));
772
818
}
773
819
774
820
listener->sendMessage (QString (" GET_MENU_ITEMS:END" ));
0 commit comments