"use strict";
class CForChangeOptions {
    constructor() {
        this.side_coords = [{}, {}];
        this.bIsDialogOpen = false;
    }
}
function IsItsDst(oData, oBr) {
    if (oData.bItsDst !== undefined) {
        return oData.bItsDst;
    }
    if (oBr && oBr.pParent) {
        return IsItsDst(oBr.pParent.fGetData(), oBr.pParent);
    }
    return false;
}
async function CreateBrowsDialogWindows(ind, oJobInList) {
    if (!sCurrJob || !oJobInList || !oJobInList.oSideCoords || IsJobActive(sCurrJob))
        throw null;
    try {
        const aFs = await SendRecivePostApiWithRetry("ListFileSystems");
        BrowseDialogForSideUrlChange(aFs.file_systems, {
            oIFDD: { conn: oJobInList.oSideCoords[ind].conn, key: oJobInList.oSideCoords[ind].sAcctKeyA },
            ind,
            sUrl2: ind ? oJobInList.left_url : oJobInList.right_url,
            bWOFiles: true,
            sDirection: oJobInList.direct
        });
    }
    catch (catchErr) {
        SendRecivePostApiCatch(catchErr, "ListFileSystems err: ", {});
    }
}
function SetFsBranch(oBrCont, oData) {
    if ((!oData.properties || oData.properties.hide_in_fs_list == "1") && !bShowHiddenFs) {
        return null;
    }
    let sIcon = oData.icon_url;
    sIcon = sIcon.trim();
    if (sIcon.substring(sIcon.length - 1) == "/") {
        sIcon = "C_Ena_Que_Fil";
    }
    const tmp = {
        sFs: oData.plain_url,
        icon: sIcon,
        display_name: oData.display_name,
        comment: "" + oData.long_description,
        size: "",
        tMod_s: -1,
        bContServList: oData.properties.can_list_servers === "1",
        bHasNoServAddr: oData.properties.no_server_addr === "1",
        bUserIdInHostname: oData.properties.has_userid_in_hostname === "1",
        bAuthOauth2: oData.properties.auth_oauth2 === "1",
        bReadOnlyFS: oData.properties.cannot_have_gsdata == "1",
        menu: (oData.plain_url.toLowerCase() == "file://" || oData.plain_url.toLowerCase() == "mtp://") ? "" : "new-account-16",
    };
    oBrCont.cont = [];
    oBrCont.folder = FOLDER_CLOSE;
    return tmp;
}
let funcForAccounts = [
    async function (oBranch, oDTP, bDontOpen) {
        const oData = oBranch.fGetData();
        oData.oConn.sUrlA = oData.sUrl;
        await ListServersRequest(oData.oConn, null, { DTP: oDTP, Branch: oBranch }, bDontOpen);
    },
    async function (oBranch, oDTP, bDontOpen) {
        const oData = oBranch.fGetData();
        oData.oConn.sUrlA = oData.sUrl;
        if (oData.oBookmarkAcc && oData.sFsHandle && oData.sFsHandleEnc) {
            if (oData.bIgnoreBookmark) {
                await ListDirForExplorerRequest(oData.sHomePath, [], { Branch: oBranch, DTP: oDTP }, { bDontOpen });
            }
            else {
                await ListDirForExplorerRequest("", [], { Branch: oBranch, DTP: oDTP }, { bDontOpen });
            }
        }
        else {
            await ConnectFsRequest(oData.oConn, null, { DTP: oDTP, Branch: oBranch }, { bWasAccessDenay: true }, bDontOpen);
        }
    }
];
function SetAccFields(oBranch) {
    let sComment = oBranch.AcctConn.sDisplayNameA;
    if (oBranch.AcctConn.sUserEmailA && sComment) {
        sComment += " (" + oBranch.AcctConn.sUserEmailA + ")";
    }
    if (!sComment) {
        sComment = oBranch.AcctConn.sUserIdA;
    }
    let sDisplayName = oBranch.DisplayName;
    if (!sDisplayName) {
        sDisplayName = GetSummary(oBranch.AcctConn) + oBranch.HomePath;
    }
    return { sDispName: sDisplayName, sComment: sComment, sUrl: oBranch.AcctConn.sUrlA, sHomePath: oBranch.HomePath };
}
function GetFieldValWithDrillUp(oTBC, sFieldName) {
    const oData = oTBC.fGetData();
    if (sFieldName in oData) {
        return oData[sFieldName];
    }
    if (oTBC.pParent) {
        return GetFieldValWithDrillUp(oTBC.pParent, sFieldName);
    }
    return "";
}
function ProcessAccBranch(oAcc, bAccContainServerList, bAccReadOnly) {
    const oAccFields = SetAccFields(oAcc);
    const oBrowsTreeData = {
        display_name: oAccFields.sDispName,
        comment: oAccFields.sComment,
        sUrl: oAccFields.sUrl,
        sHomePath: oAccFields.sHomePath,
        size: "",
        tMod_s: -1,
        sAccKey: oAcc.Key,
        bContServList: bAccContainServerList,
        bAccReadOnly: bAccReadOnly,
        oConn: oAcc.AcctConn,
        icon: "account-16",
        menu: "menu",
        fGetFsHandle: function (oCurrTBC) {
            const oThatBranch = oCurrTBC.fGetData();
            if (oThatBranch.sFsHandleEnc && !oThatBranch.bIgnoreBookmark) {
                return oThatBranch.sFsHandleEnc;
            }
            if (oThatBranch.sFsHandle) {
                return oThatBranch.sFsHandle;
            }
            if (oThatBranch.fGetFsHandle && oCurrTBC.pParent) {
                return oThatBranch.fGetFsHandle(oCurrTBC.pParent);
            }
        },
        fSetFsHandle: function (sFsHandle, bIsEnc) {
            if (bIsEnc) {
                this.sFsHandleEnc = sFsHandle;
            }
            else {
                this.sFsHandle = sFsHandle;
            }
        },
        fGetAccKey: function () { return this.sAccKey; },
        fGetUrl: function () { return this.sUrl; },
        fGetPathAndName: function (oBrowsBranch, bIsEnc) {
            if (this.oBookmarkAcc && !this.bIgnoreBookmark) {
                if (bIsEnc) {
                    return this.sHomePath;
                }
                return "";
            }
            return this.sHomePath;
        }
    };
    if (oAcc.UnnamedBookmarks && oAcc.UnnamedBookmarks.length > 0) {
        oBrowsTreeData.aBookmarks = oAcc.UnnamedBookmarks;
        for (const bm of oAcc.UnnamedBookmarks) {
            if (bm.BmkKey && bm.BmkKey == oBrowsTreeData.sHomePath) {
                if ((bm.Opts.bEncryptBodies || bm.Opts.bEncryptPaths)) {
                    oBrowsTreeData.icon = "account-enc";
                    oBrowsTreeData.oBookmarkAcc = bm;
                }
                else if ((bm.Opts.nCompressType > 1)) {
                    oBrowsTreeData.icon = "account-zip";
                    oBrowsTreeData.oBookmarkAcc = bm;
                }
            }
        }
    }
    return oBrowsTreeData;
}
async function DropMenuWithFavor(e, Branch, DTP, js) {
    const oData = Branch.fGetData();
    const jsBmList = js.find(it => it.command == "BookmarkListTable(xAddArgs)");
    if (jsBmList) {
        let nBmCnt = 0;
        const aBM = oData.aBookmarks;
        if (aBM) {
            nBmCnt = aBM.length;
        }
        jsBmList.title = GetLocaleText("Explorer_OpFavorites", ["" + nBmCnt]);
    }
    CreateDropMenuItems(js, e.clientX, e.clientY, e.clientX, e.target, false, { Branch, DTP });
}
function AccountRightBtn(e, oBranch, oDTP) {
    let zInd = Number(e.target.style.zIndex);
    if (!zInd)
        zInd = 0;
    oUpOrDownData.oDTP = oDTP;
    oUpOrDownData.oBranch = oBranch;
    TableRowClick(oDTP, oBranch, true);
    DropMenuWithFavor(e, oBranch, oDTP, jsBrowseDialogAccMenu);
}
function ProcessAccBranchForTable(oBrCont, data) {
    oBrCont.fOpenFolder = data.bContServList ? funcForAccounts[0] : funcForAccounts[1];
    oBrCont.fRightBtn = AccountRightBtn;
    oBrCont.cont = [];
    oBrCont.folder = FOLDER_CLOSE;
    oBrCont.bNoSelectWithShiftOrCtrl = true;
    return data;
}
function ProcessFolderBranchForTable(oBrCont, data) {
    if ("oConn" in data) {
        oBrCont.cont = [];
        oBrCont.folder = FOLDER_CLOSE;
    }
    if (data.bIsFile) {
        oBrCont.bHide = true;
    }
    return data;
}
function ProcessServerBranchForTable(oBrCont, data) {
    oBrCont.cont = [];
    oBrCont.folder = FOLDER_CLOSE;
    return data;
}
function FindAccountBranch(treeBr, sAccKey) {
    for (let item of treeBr._branch_.fGetData().__cont__) {
        if (item.Kyy == sAccKey)
            return item;
    }
}
function SetBrowsTreeAccounts(aAcc, xHint) {
    const oBrowsTreeData = [];
    for (const oAcc of aAcc) {
        let bAccContainServerList = false;
        let bAccReadOnly = false;
        if (typeof xHint === "boolean") {
            bAccContainServerList = xHint;
        }
        else {
            const oHint = xHint.find(item => item.AccountKey == oAcc.Key);
            if (oHint) {
                bAccContainServerList = oHint.hint_properties.list_servers;
                bAccReadOnly = oHint.hint_properties.read_only;
            }
        }
        oBrowsTreeData.push(ProcessAccBranch(oAcc, bAccContainServerList, bAccReadOnly));
    }
    return oBrowsTreeData;
}
function SetBrowsTreeServers(aBranchArr, oTreeBranchs, sUrlA, oConn, oClass) {
    const func = {
        fRightBtn: async function (e, Branch, DTP) {
            oUpOrDownData.oDTP = DTP;
            oUpOrDownData.oBranch = Branch;
            await TableRowClick(DTP, Branch, true);
            CreateDropMenuItems(jsBrowseDialogServerMenu, e.clientX, e.clientY, e.clientX, e.target, false, { Branch, DTP });
        },
        fOpenFolder: async function (oBranch, oDTP, bDontOpen) {
            await ConnectFsRequest(oBranch.fGetData().oConn, null, { DTP: oDTP, Branch: oBranch }, {}, bDontOpen);
        },
    };
    const aBTD = [];
    for (const oBranch of aBranchArr) {
        let sDispName = oBranch.sDisplayNameA;
        if (!sDispName && sDispName == "") {
            sDispName = oBranch.sUrlA;
        }
        const oTmpConn = CopyObject(oConn);
        oTmpConn.sUrlA = oBranch.sUrlA;
        let sIcon = "unknown-os";
        if (oBranch.sCommentA.toLowerCase().includes("[linux]")) {
            sIcon = "linux";
        }
        else if (oBranch.sCommentA.toLowerCase().includes("[windows]")) {
            sIcon = "windows";
        }
        else if (oBranch.sCommentA.toLowerCase().includes("[macos]")) {
            sIcon = "apple";
        }
        const oBrData = {
            sUrl: oBranch.sUrlA,
            oConn: oTmpConn,
            icon: sIcon,
            display_name: sDispName,
            size: "",
            tMod_s: (oBranch.tMod_s == 0) ? -1 : oBranch.tMod_s,
            comment: oBranch.sCommentA,
            bIsServer: true,
            menu: "menu",
            fGetUrl: function () { return this.sUrl; },
            fGetFsHandle: function (oCurrTBC) {
                const oThatBranch = oCurrTBC.fGetData();
                if (oThatBranch.sFsHandle) {
                    return oThatBranch.sFsHandle;
                }
                if (oThatBranch.fGetFsHandle && oCurrTBC.pParent) {
                    return oThatBranch.fGetFsHandle(oCurrTBC.pParent);
                }
            },
            fSetFsHandle: function (sFsHandle, bIsEnc) {
                if (bIsEnc) {
                    this.sFsHandleEnc = sFsHandle;
                }
                else {
                    this.sFsHandle = sFsHandle;
                }
            },
            fGetAccKey: function (oBrowsBranch) {
                const oData = oTreeBranchs.fGetData();
                if (oData.fGetAccKey)
                    return oData.fGetAccKey();
                return "";
            },
            fGetPathAndName: function (oBrowsBranch, bIsEnc) {
                let ret = "";
                if (oBrowsBranch.pParent) {
                    const oData = oBrowsBranch.pParent.fGetData();
                    if (oData.fGetPathAndName) {
                        ret = oData.fGetPathAndName(oBrowsBranch.pParent, bIsEnc);
                    }
                }
                return ret;
            }
        };
        aBTD.push(oBrData);
    }
    return oTreeBranchs.fAddDataArr(aBTD, { oFunc: func, fDataProcessor: ProcessServerBranchForTable, bNoSelectWithShiftOrCtrl: true, sPathFieldName: "sUrl", "sSpecValue": sUrlA, oTdProperties: oClass });
}
let aFreeSpacePlacesId = [];
async function FreeSpaceRequest(oTBC, sPath) {
    const oTarget = oTBC.fGetData();
    try {
        const sFsHandle = await oFsHandle.get(oTBC);
        const oFreeSpaceData = await SendRecivePostApiWithRetry("GetFreeDiskSpace", { "filesys_handle": sFsHandle, "path": sPath });
        const oDiscSpaces = ConvertBytes(oFreeSpaceData.total, oFreeSpaceData.available);
        if (!Number.isNaN(oDiscSpaces.nSpace1)) {
            oTarget.comment += (oTarget.comment ? ", " : "") + "Total: " + RoundTo3Digits(oDiscSpaces.nSpace1) + " " + oDiscSpaces.unit;
        }
        if (!Number.isNaN(oDiscSpaces.nSpace2)) {
            oTarget.comment += (oTarget.comment ? ", " : "") + "Free: " + RoundTo3Digits(oDiscSpaces.nSpace2) + " " + oDiscSpaces.unit;
        }
    }
    catch (oErr) {
    }
}
async function ShowFreeSpace(oDTP) {
    if (!aFreeSpacePlacesId || aFreeSpacePlacesId.length <= 0)
        return;
    for (const it of aFreeSpacePlacesId) {
        if (it.branch.cont && it.branch.cont.length > it.ind) {
            const oRealBranch = it.branch.cont.find(br => br.indJs == it.ind);
            if (oRealBranch) {
                it.branch = oRealBranch;
            }
        }
        await FreeSpaceRequest(it.branch, it.path);
    }
    aFreeSpacePlacesId = [];
    if (oDTP) {
        oDTP.ShowTable();
    }
}
function IsFolderInBookmarks(sPath, oTreeBranchs) {
    let sServerAndPath = "";
    while (oTreeBranchs) {
        const oData = oTreeBranchs.fGetData();
        if (oData.bIsServer) {
            sServerAndPath = oData.sUrl;
        }
        if (oData.aBookmarks) {
            sServerAndPath = GetServerName(oData.oConn.sUrlA, sServerAndPath, oData.oConn.sUserIdA, true) + sPath;
            const oTmpBm = oData.aBookmarks.find(it => it.BmkKey === sServerAndPath);
            if (oTmpBm && IsBmEncOrZip(oTmpBm.Opts)) {
                const oConn1 = CopyObject(oData.oConn);
                oConn1.sUrlA += sPath;
                return { bm: oTmpBm, conn: oConn1 };
            }
            return;
        }
        oTreeBranchs = oTreeBranchs.pParent;
    }
}
function IsBookmarkInFolder(oBDE) {
    const oData = oBDE.Branch.fGetData();
    return (!oData.oBookmark && !oData.oBookmarkAcc) ? (oData.bIgnoreBookmark ? -1 : 0) : (oData.bIgnoreBookmark ? 1 : 2);
}
function IsFolderContTable(oBDE) {
    if (oBDE.DTP && oBDE.DTP.oParentBr)
        return true;
    return false;
}
function AddBookmarkToAcc(oBM, oTreeBranchs) {
    while (oTreeBranchs) {
        const oData = oTreeBranchs.fGetData();
        if (oData.sAccKey) {
            if (!oData.aBookmarks) {
                oData.aBookmarks = [];
            }
            oData.aBookmarks.push(oBM);
            return;
        }
        oTreeBranchs = oTreeBranchs.pParent;
    }
}
function GetBookmarkInFolder(sPath, oTreeBranchs) {
    const oData = oTreeBranchs.fGetData();
    if (oData.oBookmark) {
        const oConn1 = CopyObject(oData.oConn);
        oConn1.sUrlA = sPath;
        return { bm: oData.oBookmark, conn: oConn1 };
    }
}
function GetBaseFsHandle(oBr) {
    while (oBr.pParent) {
        const oData = oBr.pParent.fGetData();
        if (oData.sFsHandle && (oData.sAccKey || oData.bIsServer)) {
            return oData.sFsHandle;
        }
        oBr = oBr.pParent;
    }
    return "";
}
const MIN_BAD_ENC_ITEM = 3;
const MAX_CHECK_ENC_ITEM = 3000;
function GsFolderLooksEncrypted(alsItems, nMaxBadNamesPercent = 100) {
    const nItemsEff = alsItems.length;
    if (nItemsEff < 1) {
        return "";
    }
    const nCheckingItems = Math.min(nItemsEff, MAX_CHECK_ENC_ITEM);
    const nStep = nItemsEff / nCheckingItems;
    const nBadNamesThreshold = (nCheckingItems < MIN_BAD_ENC_ITEM * 2) ?
        Math.floor(nCheckingItems / 2) :
        Math.max(((nMaxBadNamesPercent >= 100) ?
            0 : (1 - nMaxBadNamesPercent * 0.01)) * nCheckingItems, MIN_BAD_ENC_ITEM);
    let nBadNames = 0;
    let i = 0;
    let nCnt = 0;
    for (; i < nItemsEff;) {
        if (!alsItems[i].sNameA.endsWith(".gszip")) {
            nBadNames++;
            if (nBadNames > nBadNamesThreshold) {
                break;
            }
        }
        nCnt += nStep;
        i = Math.floor(nCnt);
    }
    if (i >= nItemsEff) {
        return "gszip";
    }
    i = 0;
    nCnt = 0;
    nBadNames = 0;
    for (; i < nItemsEff;) {
        if (!GsItemNameLooksEncrypted(alsItems[i].sNameA)) {
            nBadNames++;
            if (nBadNames > nBadNamesThreshold) {
                return "";
            }
        }
        nCnt += nStep;
        i = Math.floor(nCnt);
    }
    return "encrypted";
}
function GsItemNameLooksEncrypted(sItemName) {
    if (sItemName.length < 23) {
        return false;
    }
    return /^[A-Za-z0-9+\/_-]*$/.test(sItemName);
}
function SetBrowsTreeFolders(aBranchArr, sPath, oTreeBranchs, aExcludeNames, bWOFiles) {
    const aBrTreeData = [];
    const aFunc = [];
    const oData = oTreeBranchs.fGetData();
    let nFolderCnt = 0;
    if (!oData.oBookmark && !oData.oBookmarkAcc && !IsIntoEncOrZip(oTreeBranchs)) {
        switch (GsFolderLooksEncrypted(aBranchArr)) {
            case "gszip":
                {
                    if (oData.icon.startsWith("account")) {
                        oData.icon = "account-prob-zip";
                    }
                    else {
                        oData.icon = "gs-prob-zip";
                    }
                    oData.bIgnoreBookmark = true;
                }
                break;
            case "encrypted":
                {
                    if (oData.icon.startsWith("account")) {
                        oData.icon = "account-prob-enc";
                    }
                    else {
                        oData.icon = "folder-prob-enc";
                    }
                    oData.bIgnoreBookmark = true;
                }
                break;
        }
    }
    for (const oBranch of aBranchArr) {
        if (bWOFiles && (oBranch.bIsFile || aExcludeNames.includes(oBranch.sNameA))) {
            continue;
        }
        let sDispName = oBranch.sDisplayName + "";
        if (sDispName == "") {
            sDispName = "" + oBranch.sNameA;
        }
        let sComment = oBranch.sComment + "";
        if (!sPath)
            sPath = "";
        const sfPathAndName = sPath + "/" + oBranch.sNameA;
        if (oBranch.bIsLink) {
            sComment = "->" + sComment;
        }
        let oBrTreeData;
        const func = {};
        if (oBranch.bIsFile) {
            oBrTreeData = {
                icon: GetFileExtension(oBranch.sNameA),
                display_name: sDispName,
                size: oBranch.size,
                tMod_s: (oBranch.tMod_s == 0) ? -1 : oBranch.tMod_s,
                comment: sComment,
                sName: oBranch.sNameA,
                menu: "menu",
                bIsFile: true
            };
            func.fRightBtn = function (e, Branch, DTP) {
                oUpOrDownData.oBranch = Branch;
                oUpOrDownData.oDTP = DTP;
                TableRowClick(DTP, Branch);
                CreateDropMenuItems(jsBrowseDialogFileMenu, e.clientX, e.clientY, e.clientX, e.target, false, { Branch, DTP });
            };
            func.fDblclick = (oBr, oDTP) => {
                OpenFileByLink({ DTP: oDTP, Branch: oBr });
            };
        }
        else {
            nFolderCnt++;
            oBrTreeData = {
                oConn: oData.oConn,
                icon: "folder",
                display_name: sDispName,
                comment: sComment,
                sName: oBranch.sNameA,
                size: (oBranch.size == '0') ? "" : oBranch.size,
                tMod_s: (oBranch.tMod_s == 0) ? -1 : oBranch.tMod_s,
                menu: "menu",
            };
            const oBm = IsFolderInBookmarks(sfPathAndName, oTreeBranchs);
            if (oBm) {
                if (oBm.bm.Opts.nCompressType > 0) {
                    if (oBrTreeData.icon.startsWith("account")) {
                        oBrTreeData.icon = "account-prob-zip";
                    }
                    else {
                        oBrTreeData.icon = "gs-zip";
                    }
                }
                else {
                    if (oBrTreeData.icon.startsWith("account")) {
                        oBrTreeData.icon = "account-prob-enc";
                    }
                    else {
                        oBrTreeData.icon = "folder-enc";
                    }
                }
                oBrTreeData.oBookmark = oBm.bm;
            }
            else if (oBranch.bIsLink) {
                oBrTreeData.icon = "folder_link";
            }
            func.fRightBtn = function (e, Branch, DTP, bFromEmptySpace) {
                TableRowClick(DTP, Branch, true);
                oUpOrDownData.oBranch = Branch;
                oUpOrDownData.oDTP = DTP;
                CreateDropMenuItems(jsBrowseDialogFolderMenu, e.clientX, e.clientY, e.clientX, e.target, false, { Branch, DTP, bFromEmptySpace });
            };
            func.fOpenFolder = async function (oBranch, oDTP, bDontOpen, sNameForMark) {
                const oDataOpen = oBranch.fGetData();
                if (oBranch.cont && oBranch.cont.length === 0 && oDataOpen.__oAbort__ && oDataOpen.__oAbort__.signal.aborted) {
                    oDataOpen.__oAbort__ = new AbortController();
                }
                await ListDirForExplorerRequest(oDataOpen.fGetPathAndName(oBranch), null, { "DTP": oDTP, "Branch": oBranch }, { bDontOpen, sNameForMark });
            };
        }
        oBrTreeData.fGetPathAndName = function (oBrowsBranch, bIsEnc) {
            if (!("sName" in this) || this.oBookmark && !this.bIgnoreBookmark) {
                if (bIsEnc && this.oBookmark && this.oBookmark.BmkKey) {
                    return this.oBookmark.BmkKey;
                }
                return "";
            }
            let ret = "/" + this.sName;
            if (oBrowsBranch.pParent) {
                const oData = oBrowsBranch.pParent.fGetData();
                if (oData.fGetPathAndName) {
                    ret = oData.fGetPathAndName(oBrowsBranch.pParent, bIsEnc) + ret;
                }
            }
            return ret;
        };
        oBrTreeData.fGetUrl = function () {
            if (oData.fGetUrl)
                return oData.fGetUrl();
            return "";
        };
        oBrTreeData.fSetFsHandle = function (sFsHandleInp, bIsEnc) {
            if (bIsEnc) {
                this.sFsHandleEnc = sFsHandleInp;
            }
            else {
                oData.fSetFsHandle(sFsHandleInp);
            }
        };
        oBrTreeData.fGetAccKey = function () {
            if (oData.fGetAccKey)
                return oData.fGetAccKey();
            return "";
        };
        oBrTreeData.fGetFsHandle = function (oCurrTBC) {
            if (!oCurrTBC)
                return "";
            const oThatBranch = oCurrTBC.fGetData();
            if (oThatBranch.sFsHandleEnc && !oThatBranch.bIgnoreBookmark || oThatBranch.sFsHandle) {
                return oThatBranch.sFsHandleEnc || oThatBranch.sFsHandle;
            }
            if (oThatBranch.fGetFsHandle && oCurrTBC.pParent) {
                return oThatBranch.fGetFsHandle(oCurrTBC.pParent);
            }
            throw "";
        };
        if (oBranch.dwAbilities & GS_AB_IS_DISK) {
            aFreeSpacePlacesId.push({ branch: oTreeBranchs, path: sfPathAndName, ind: aBrTreeData.length });
        }
        aBrTreeData.push(oBrTreeData);
        aFunc.push(func);
    }
    return { aData: aBrTreeData, aFunc: aFunc, nFolderCnt };
}
function AddErrorToTree(error, oBDE) {
    if (!oBDE.DTP || !oBDE.Branch) {
        ErrorMsgShow(error.message, { sErrType: "Job Tree error: ", eGoal: "both", bNoCurrJobName: true });
    }
    else {
        const bFolderOpen = oBDE.Branch.folder == FOLDER_OPEN;
        oBDE.Branch.fClear();
        let tmp = {
            icon: "C_Ena_Att_Fill",
            display_name: "<div style='color:red; white-space: normal;'>" + error.message + "</div>",
            comment: (error.data && error.data.error_num) ? "<div style='color:red;'>Error " + error.data.error_num + "</div>" : "",
            menu: "",
        };
        oBDE.Branch.fAddData(tmp, {});
        if (bFolderOpen) {
            oBDE.Branch.folder = FOLDER_OPEN;
            oBDE.DTP.ShowTable();
        }
        oBDE.Branch.bError = true;
    }
}
function CleanAndCloseBranch(oBDE) {
    if (oBDE.Branch) {
        oBDE.Branch.fClear();
        oBDE.Branch.folder = FOLDER_CLOSE;
    }
    oBDE.DTP.ShowTable();
}
function RefreshAcc(oBDE) {
    const oData = oBDE.Branch.fGetData();
    const oConn = { conn: oData.oConn, key: oData.sAccKey };
    oConn.conn.sUrlA = oData.sUrl + oData.fGetPathAndName(oBDE.Branch);
    oBDE.Branch = GetEldestParent(oBDE.Branch);
    CleanAndCloseBranch(oBDE);
    ListAccForExplorerRequest(oConn, oBDE);
}
function GetEldestParent(oBranch) {
    if (oBranch.pParent) {
        return GetEldestParent(oBranch.pParent);
    }
    else {
        return oBranch;
    }
}
let nWaitBoxFilling = 0;
function WaitBoxFilling() {
    let aWaitBoxes = document.getElementsByClassName("waiting_box");
    nWaitBoxFilling++;
    for (const el of aWaitBoxes) {
        const domEl = el;
        SetWaitingSimbols1(domEl, nWaitBoxFilling);
    }
}
setInterval(WaitBoxFilling, 1000);
function ShowWaitingTimer(text, oBDE, par = {}) {
    if (par.bDontOpen)
        return;
    oBDE.Branch.fWaitingExit = function () {
        if (oBDE.Branch.fGetData().__oAbort__) {
            oBDE.Branch.fGetData().__oAbort__.abort();
        }
        oBDE.Branch.fClear();
        oBDE.DTP.ShowTable();
    };
    oBDE.Branch.fSetWaitingTimer(text, false, par.bForce);
    oBDE.Branch.folder = FOLDER_OPEN;
    oBDE.DTP.ShowTable();
}
function SetUrlToDom(dom, sUrl) {
    if (dom.tagName.toUpperCase() == "INPUT") {
        const input = dom;
        input.value = sUrl;
        input.dispatchEvent(new Event('input'));
    }
    else {
        dom.innerHTML = sUrl;
    }
}
async function FolderInfoRequest(sFsHandle, oBDE, oData, bNessessOfClick) {
    try {
        let sPath = oData.fGetPathAndName(oBDE.Branch, true);
        const oBM = GetBM(oBDE.Branch);
        if (oBM) {
            sPath = sPath.slice(oBM.BmkKey.length);
        }
        const oParams = { "filesys_handle": sFsHandle, "path": sPath, "get_owner": true, "get_acl": true };
        const oAns = await RequestWithReconnect("GetInfo", oParams, oBDE);
        oData.bCanBeJobSide = CanBeJobSide(oAns.info.dwAbilities, oBDE.Branch, IsItsDst(oData, oBDE.Branch));
        oData.bCanCreateFolder = CanFolderToBeCreateIn(oAns.info.dwAbilities);
        if (bNessessOfClick && oBDE.DTP) {
            await TableRowClick(oBDE.DTP, oBDE.Branch, true);
        }
        oAns.info.acl = oAns.acl;
        oAns.info.owner = oAns.owner;
        return oAns.info;
    }
    catch (oErr) {
        CatchErrProcess(oErr, "", { eGoal: "console" });
        throw "";
    }
}
async function FolderInfoRequestForExplorer(sFsHandle, oBDE, oData) {
    try {
        let sPath = oData.fGetPathAndName(oBDE.Branch, true);
        const oBM = GetBM(oBDE.Branch);
        if (oBM) {
            sPath = sPath.slice(oBM.BmkKey.length);
        }
        const oParams = { "filesys_handle": sFsHandle, "path": sPath };
        const oAns = await RequestWithReconnect("GetInfo", oParams, oBDE);
        oData.bCanCreateFolder = CanFolderToBeCreateIn(oAns.info.dwAbilities);
        oData.bCanCreateFile = CanFolderToBeCreateIn(oAns.info.dwAbilities);
    }
    catch { }
}
async function SetBeJobSideAbility(oData, oBDE) {
    if (!oBDE.Branch || oData.bCanBeJobSide !== undefined)
        return;
    if (IsIntoEncOrZip(oBDE.Branch)) {
        oData.bCanBeJobSide = false;
    }
    try {
        if (oData.sFsHandleEnc) {
            let sFsHandle = oData.sFsHandle;
            if (!sFsHandle && oBDE.Branch && oBDE.Branch.pParent) {
                sFsHandle = await oFsHandle.get(oBDE.Branch.pParent);
            }
            if (!sFsHandle)
                return;
            const ans = await FolderInfoRequest(sFsHandle, oBDE, oData, true);
            oFsHandle.del(sFsHandle);
            return ans;
        }
        const sFsHandle2 = await oFsHandle.get(oBDE.Branch);
        const ans = await FolderInfoRequest(sFsHandle2, oBDE, oData, true);
        oFsHandle.del(sFsHandle2);
        return ans;
    }
    catch {
        throw null;
    }
}
async function GetFolderInfoWithEnc(oData, oBDE, bWinStyle) {
    try {
        const btmp = oData.bIgnoreBookmark;
        oData.bIgnoreBookmark = true;
        const sFsHandle = await oFsHandle.get(oBDE.Branch);
        const oAns = await FolderInfoRequest(sFsHandle, oBDE, oData, !bWinStyle);
        oData.bIgnoreBookmark = btmp;
        return oAns;
    }
    catch {
        throw null;
    }
}
function GetBM(oBranch) {
    if (!oBranch)
        return;
    let bmBranch = oBranch.fFindEl("", "oBookmark", "up");
    if (bmBranch) {
        const oBmData = bmBranch.fGetData();
        if (!oBmData.bIgnoreBookmark) {
            return oBmData.oBookmark;
        }
    }
    else {
        bmBranch = oBranch.fFindEl("", "oBookmarkAcc", "up");
        if (bmBranch) {
            const oBmData = bmBranch.fGetData();
            if (!oBmData.bIgnoreBookmark) {
                return oBmData.oBookmarkAcc;
            }
        }
    }
    return;
}
async function SetNewJobUrl(oBDE, ind, sUrl2, oFCO, oSUP = {}) {
    if (!oSUP.dom) {
        return "";
    }
    const oTableBranch = oBDE.Branch;
    const oData = oTableBranch.fGetData();
    if (oData.bIsFile) {
        if (oSUP.domSaveBtn) {
            oSUP.domSaveBtn.disabled = true;
        }
        return "";
    }
    let sUrl = GetFieldValWithDrillUp(oTableBranch, "sFs");
    let sfPathAndName = "";
    if (oData.fGetPathAndName) {
        sfPathAndName = oData.fGetPathAndName(oTableBranch, true);
    }
    if (oData.oConn && IsFsGST(oData.oConn.sUrlA)) {
        const sServerName = GetGstServerName(oData.oConn.sUrlA, oData.oConn.sUserIdA);
        if (sServerName && sfPathAndName.startsWith(sServerName)) {
            sfPathAndName = sfPathAndName.slice(sServerName.length);
        }
    }
    if (oData.fGetUrl) {
        sUrl = oData.fGetUrl() + sfPathAndName;
        if (oData.sName) {
            SetUrlToDom(oSUP.dom, GetPathForShow(sUrl));
        }
        else {
            SetUrlToDom(oSUP.dom, sUrl);
        }
    }
    else {
        SetUrlToDom(oSUP.dom, sUrl);
    }
    if (!oData.oBookmark && !oData.oBookmarkAcc && (oTableBranch.fFindEl("", "oBookmark", "up") || oTableBranch.fFindEl("", "oBookmarkAcc", "up"))) {
        if (oSUP.domSaveBtn) {
            oSUP.domSaveBtn.disabled = true;
        }
        SetDomDisplayAndInnerHtml(oSUP.domResume, "", { text: GetLocaleText("Browse_Hint_CryptLevel"), class: "job_errors", img: "error" });
        return sUrl;
    }
    if (!("bCanBeJobSide" in oData) && oSUP.bMouseClick) {
        if (oData.sAccKey) {
            if (!oData.bContServList) {
                await ConnectFsRequest(oData.oConn, [], oBDE, { dNeedBranchInfo: true });
            }
        }
        else if (oData.bIsServer) {
            await ConnectFsRequest(oData.oConn, [], oBDE, { dNeedBranchInfo: true });
        }
        else {
            try {
                await SetBeJobSideAbility(oData, oBDE);
            }
            catch { }
        }
    }
    if (!oData.bCanBeJobSide) {
        if (oSUP.domSaveBtn) {
            oSUP.domSaveBtn.disabled = true;
        }
        SetDomDisplayAndInnerHtml(oSUP.domResume, "", { text: GetLocaleText("Browse_Hint_BadLevel"), class: "job_errors", img: "error" });
        return sUrl;
    }
    if (DoJobPathsContainsOneAnother(sUrl, sUrl2)) {
        oData.bCanBeJobSide = true;
        SetDomDisplayAndInnerHtml(oSUP.domResume, "", {
            text: GetLocaleText("Str_ErrOfChsePaths") + "<br/>" +
                GetLocaleText("Browse_Hint_AnotherSide") + GetPathForShow(sUrl2),
            class: "err_above_tree non_term_error_cell", img: "warning"
        });
    }
    else {
        SetDomDisplayAndInnerHtml(oSUP.domResume, "", { text: GetLocaleText("Browse_Hint_Select"), class: "job_success", img: "success" });
    }
    if (IsFsGST(GetFieldValWithDrillUp(oTableBranch, "sFs"))) {
        sfPathAndName = ExtractSubstring(sUrl, "://", "." + oData.oConn.sUserIdA) + sfPathAndName;
    }
    if (oSUP.domSaveBtn) {
        oSUP.domSaveBtn.disabled = false;
    }
    if (oData.oBookmark || oData.oBookmarkAcc) {
        oFCO.side_coords[ind].Opts = oData.oBookmark ? oData.oBookmark.Opts : oData.oBookmarkAcc.Opts;
    }
    oFCO.side_coords[ind].conn = CopyObject(oData.oConn);
    oFCO.side_coords[ind].conn.sUrlA = sUrl;
    oFCO.side_coords[ind].sAcctKeyA = oData.fGetAccKey();
    oFCO.side_coords[ind].sServerDirA = sfPathAndName;
    oFCO.side_coords[ind].sPasswordEncMasterA = oData.sPasswordEncMasterA;
    return sUrl;
}
function SetNewUrlForExplorer(oTableBranch, dom, sAddPath) {
    if (!dom)
        return "";
    const oData = oTableBranch.fGetData();
    let sfPathAndName = "";
    if (oData.fGetPathAndName) {
        sfPathAndName = oData.fGetPathAndName(oTableBranch, true);
    }
    if (oData.oConn && IsFsGST(oData.oConn.sUrlA)) {
        const sServerName = GetGstServerName(oData.oConn.sUrlA, oData.oConn.sUserIdA);
        if (sServerName && sfPathAndName.startsWith(sServerName)) {
            sfPathAndName = sfPathAndName.slice(sServerName.length);
        }
    }
    sfPathAndName += sAddPath;
    let sPathForShow = "";
    if (oData.fGetUrl) {
        sPathForShow = GetPathForShow(oData.fGetUrl() + sfPathAndName);
    }
    else {
        sPathForShow = GetPathForShow(GetFieldValWithDrillUp(oTableBranch, "sFs"));
    }
    SetUrlToDom(dom, sPathForShow);
    return sPathForShow;
}
function GetPathForShow(oJobUrlAndPath) {
    if (!oJobUrlAndPath) {
        return "";
    }
    if (oJobUrlAndPath.startsWith("\/")) {
        return oJobUrlAndPath.substring(1);
    }
    else if (oJobUrlAndPath.startsWith("file:\/\/")) {
        return oJobUrlAndPath.substring(8);
    }
    return oJobUrlAndPath;
}
function GetPathFromShow(oJobUrlAndPath) {
    if (!oJobUrlAndPath) {
        return "";
    }
    if (!oJobUrlAndPath.includes("://")) {
        return "file://" + oJobUrlAndPath;
    }
    return oJobUrlAndPath;
}
async function RefreshBrowseBranch(sType, oBDE) {
    if (!oBDE.Branch || !oBDE.DTP)
        return;
    oBDE.Branch.fClear();
    if (oBDE.Branch.folder === FOLDER_EMPTY || oBDE.Branch.folder === FOLDER_IS_HIDE_IN || oBDE.Branch.folder === FOLDER_NO_FLDR_IN) {
        oBDE.Branch.folder = FOLDER_CLOSE;
    }
    switch (sType) {
        case "Normal":
            {
                const oData = oBDE.Branch.fGetData();
                if ((oData.oBookmarkAcc || oData.oBookmark) && !oData.bIgnoreBookmark) {
                    oData.bIgnoreBookmark = true;
                }
            }
            break;
        case "Encrypt":
            {
                const oData = oBDE.Branch.fGetData();
                delete oData.bIgnoreBookmark;
                if (!oData.oBookmarkAcc && !oData.oBookmark) {
                    const oFO = new COpts;
                    oFO.sRawPasswd = "";
                    oFO.sRepPasswd = "";
                    const oBM = new CBookmark;
                    const sUrlA = oData.fGetPathAndName(oBDE.Branch);
                    oBM.BmkKey = sUrlA;
                    oBM.sServerDirA = sUrlA;
                    oBM.sAcctKeyA = oData.fGetAccKey();
                    const oMeta = { conn: oData.oConn, sServerDirA: sUrlA, sAcctKeyA: oBM.sAcctKeyA };
                    if (oData.icon == "gs-prob-zip" || oData.icon == "account-prob-zip") {
                        oFO.nCompressType = 2;
                        jsFloatMenu["BookmarkZipOptions"].meta = oMeta;
                        CreateFloatMenu(jsFloatMenu["BookmarkZipOptions"], { width: "650px", top: "30%" }, oFO, { minWidth: "450px", minHeight: "200px" }).promise.then(data => {
                            oFO.sRepPasswd = oFO.sRawPasswd;
                            if (data.command == "save") {
                                ProcessingChangeFolderOptions(oFO, oBM, sUrlA, -1, oBDE);
                            }
                        }).catch(() => { }).finally(() => { delete jsFloatMenu["BookmarkZipOptions"].meta; });
                    }
                    else {
                        oFO.nCompressType = 1;
                        jsFloatMenu["BookmarkEncOptions"].meta = oMeta;
                        CreateFloatMenu(jsFloatMenu["BookmarkEncOptions"], { width: "650px", top: "30%" }, oFO, { minWidth: "450px", minHeight: "200px" }).promise.then(data => {
                            oFO.sRepPasswd = oFO.sRawPasswd;
                            if (data.command == "save") {
                                ProcessingChangeFolderOptions(oFO, oBM, sUrlA, -1, oBDE);
                            }
                        }).catch(() => { }).finally(() => { delete jsFloatMenu["BookmarkEncOptions"].meta; });
                    }
                    return;
                }
            }
            break;
    }
    try {
        if (oSavedData.eExplorerMode == 'detal_mode' || oSavedData.eExplorerMode == 'med_icon_mode') {
            if (oBDE.DTP.oFolderContTable) {
                delete oBDE.DTP.oFolderContTable.oParentBr;
            }
            await TableRowClick(oBDE.DTP, oBDE.Branch, true);
            if (oBDE.Branch.folder === FOLDER_OPEN) {
                await TableOpenFolder(oBDE.DTP, oBDE.Branch);
            }
        }
        else {
            await TableOpenFolder(oBDE.DTP, oBDE.Branch);
        }
    }
    catch { }
}
function FolderAndFileInfoProcessing(oInfo, sPath, sName) {
    const eObjectType = oInfo.bIsLink ? (oInfo.bIsFile ? "link to file" :
        "link to folder") :
        (oInfo.bIsFile ? "file" :
            "folder");
    return "<table class='folder_info'>" +
        "<tr><td>Name</td><td>" + (sName || oInfo.sDisplayName || oInfo.sNameA) + "</td></tr>" +
        "<tr><td>Type</td><td>" + eObjectType + "</td></tr>" +
        "<tr><td>Location</td><td>" + sPath + "</td></tr>" +
        "<tr><td>Size</td><td>" + GetSizeAndUnit(oInfo.size) + " (" + GetLocalNumber(oInfo.size) + " bytes)</td></tr>" +
        "<tr><td>Created</td><td>" + GetDTString(oInfo.tCre_s) + "</td></tr>" +
        "<tr><td>Modifed</td><td>" + GetDTString(oInfo.tMod_s) + "</td></tr>" +
        "<tr><td>Attriburtes</td><td>" + SibFileAttrToStrA(oInfo.dwBitAttrs) + "</td></tr>" +
        "<tr><td>Owner</td><td>" + (oInfo.owner || "") + "</td></tr>" +
        "<tr><td>ACL</td><td>" + (oInfo.acl || "") + "</td></tr>" +
        "</table>";
}
function OnChangeBDT(el, oMenu) {
    if (!oMenu)
        return;
    const domSaveBtn = document.getElementById("save_btn_" + oMenu.id);
    if (domSaveBtn) {
        domSaveBtn.disabled = oMenu.blockSaveBtmMap.size > 0;
    }
    const domTestBtn = document.getElementById("test_btn_" + oMenu.id);
    if (domTestBtn) {
        domTestBtn.disabled = false;
    }
}
function GetFormForCodeEnter(sPrompt, bSms) {
    const aCont = [
        { type: "text", title: sPrompt, id: "prompt" },
        { type: "textfield", title: "", value: "s2FACode", },
    ];
    if (bSms) {
        aCont.push({ type: "button", title: "Btn_SendSms", command: "Request2FaSms", value: "conn" });
    }
    return {
        title: "Title_CodeFor2FA",
        bottom_box: [
            { title: "Btn_Send", close: true, "command": "save", default: true },
            { title: "Btn_Cancel", close: true, }
        ], cont: [
            { title: "", cont: aCont }
        ]
    };
}
async function Request2FaSms(sId, conn) {
    const domPrompt = document.getElementById("prompt_" + sId);
    try {
        const oTwoFactor = await SendRecivePostApiWithRetry("StartTwoFactorAuth", { "conn": conn, "channel": "sms" });
        if (domPrompt) {
            domPrompt.innerHTML = oTwoFactor.prompt;
        }
    }
    catch (oErr) {
        if (oErr && oErr.error && oErr.error.message) {
            SetDomDisplayAndInnerHtml(domPrompt, "", { text: oErr.error.message, class: "job_errors", img: "error" });
        }
        else {
            SetDomDisplayAndInnerHtml(domPrompt, "", { text: GetLocaleText("Str_AuthSmthngWntWrng"), class: "job_errors", img: "error" });
        }
    }
}
async function Send2FACode(obj2FACode, sPrompt) {
    const bSms = obj2FACode.conn.sUrlA.startsWith("icloud://") || obj2FACode.conn.sUrlA.startsWith("iphotos://");
    const oMenu = CreateFloatMenu(GetFormForCodeEnter(sPrompt, bSms), { width: "400px", top: "30%" }, obj2FACode);
    try {
        await oMenu.promise;
        await SendRecivePostApiWithRetry("CompleteTwoFactorAuth", { "conn": obj2FACode.conn, "code": obj2FACode.s2FACode });
        return;
    }
    catch (oErr) {
        if (oErr && oErr.error) {
            if (oErr.error.data && oErr.error.data.error_str == "needs_custom_gui_auth") {
                try {
                    await Send2FACode(obj2FACode, oErr.error.message);
                    return;
                }
                catch { }
            }
            else if (oErr.error.message) {
                HtmlErrBox(oErr.error.message, GetLocaleText("Err_AccountCreationError"));
            }
            else {
                HtmlErrBox(GetLocaleText("Str_AuthSmthngWntWrng"), GetLocaleText("Err_AccountCreationError"));
            }
        }
        else {
            HtmlErrBox(GetLocaleText("Str_AuthSmthngWntWrng"), GetLocaleText("Err_AccountCreationError"));
        }
    }
    throw null;
}
async function StartTwoFactorAuth(oConn) {
    try {
        const o2FARes = await SendRecivePostApiWithRetry("StartTwoFactorAuth", { "conn": oConn });
        const obj2FACode = { s2FACode: "", conn: oConn };
        await Send2FACode(obj2FACode, o2FARes.prompt);
    }
    catch (oErr) {
        CatchErrProcess(oErr, GetLocaleText("Err_AccountCreationError"), { bNoCurrJobName: true });
        throw null;
    }
}
async function SetRealURL(oConn, obj) {
    try {
        if (IsFsGST(oConn.sUrlA) && IsServAddr(oConn.sUrlA) || !IsFsGST(oConn.sUrlA) && (!obj.bContServList || !obj.bHasNoServAddr)) {
            return oConn;
        }
        const data = await SendRecivePostApiWithRetry("ListServers", { "conn": oConn });
        if (data.servers && data.servers.length > 0) {
            if (IsFsGST(oConn.sUrlA)) {
                data.out_conn.sUrlA = obj.sFsName + data.out_conn.sUserIdA + ".goodsync";
                return data.out_conn;
            }
            else {
                oConn.sUrlA = data.servers[0].sUrlA;
                return oConn;
            }
        }
        else {
            throw null;
        }
    }
    catch (oErr) {
        if (oErr && oErr.error && oErr.error.data && oErr.error.data.error_str == "needs_custom_gui_auth") {
            try {
                await StartTwoFactorAuth(oConn);
                return oConn;
            }
            catch (oErr2) {
                throw oErr2;
            }
        }
        else {
            throw oErr;
        }
    }
}
function ChangeWaitBox(id, bSet) {
    const dom = document.getElementById(id);
    if (dom) {
        if (bSet) {
            dom.classList.add("waiting_box");
        }
        else {
            dom.classList.remove("waiting_box");
        }
    }
    return dom;
}
async function CreateAccWithCheck(oConn, bListServ, sHomePath, oDTE, oPar = {}) {
    let sKey = "";
    if (oPar.jsAccData && oPar.jsAccData.Key) {
        sKey = oPar.jsAccData.Key;
    }
    try {
        if (bListServ) {
            await SendRecivePostApiWithRetry("ListServers", { "conn": oConn }, { domMenu: oPar.oMenu });
        }
        else {
            await SendRecivePostApiWithRetry("ConnectFS", { "folder_coords": { "conn": oConn, "sAcctKeyA": sKey } }, { domMenu: oPar.oMenu });
        }
        await CreateAccountRequest(oConn, sHomePath, oDTE, oPar);
    }
    catch (oErr) {
        if (oErr && oErr.error) {
            if (oErr.error.data && oErr.error.data.error_str == "needs_custom_gui_auth") {
                try {
                    await StartTwoFactorAuth(oConn);
                    await CreateAccountRequest(oConn, sHomePath, oDTE, oPar);
                }
                catch (oErr2) {
                    if (oErr2 && oErr2.error && oErr2.error.message) {
                        HtmlErrBox(oErr2.error.message, GetLocaleText("Err_AccountCreationError"));
                    }
                    CloseFloatMenu(oPar.oMenu);
                }
            }
            else if (oErr.error.data && oErr.error.data.error_str == "auth_rejected") {
                HtmlErrBox(oErr.error.message, GetLocaleText("Err_AccountCreationError"));
                if (oPar.oMenu) {
                    ChangeWaitBox("test_results_" + oPar.oMenu.id);
                }
            }
            else {
                if (oErr.error.message) {
                    HtmlErrBox(oErr.error.message, GetLocaleText("Err_AccountCreationError"));
                }
                CloseFloatMenu(oPar.oMenu);
            }
        }
    }
}
async function CreateAccRealUrlGetting(oConnBefore, sHomePath, oBDE, obj, oPar) {
    try {
        const oConnAfter = await SetRealURL(oConnBefore, obj);
        if (obj.bAuthOauth2) {
            CreateAccountRequest(oConnAfter, sHomePath, oBDE, oPar);
        }
        else if (IsFsGST(oConnAfter.sUrlA) && (!IsServAddr(oConnAfter.sUrlA) || oConnAfter.sUrlA.endsWith(":\/\/" + oConnAfter.sUserIdA + ".goodsync"))) {
            CreateAccWithCheck(oConnAfter, true, sHomePath, oBDE, oPar);
        }
        else {
            CreateAccWithCheck(oConnAfter, false, sHomePath, oBDE, oPar);
        }
    }
    catch (oErr) {
        CatchErrProcess(oErr, GetLocaleText("Err_AccountCreationError"), { eGoal: "both", bNoCurrJobName: true });
        CloseFloatMenu(oPar.oMenu);
    }
}
async function AccTestWithServList(oConn, obj, sId, domPlace) {
    try {
        const oData = await SendRecivePostApiWithRetry("ListServers", { "conn": oConn });
        HtmlMsgbox(GetLocaleText("Browse_Account_TestSuccess"), "", { class: "short_message" });
        obj.conn = oData.out_conn;
        if (IsFsGST(obj.sFsName)) {
            obj.conn.sUrlA = obj.sFsName + obj.conn.sUserIdA + ".goodsync";
        }
        if (domPlace) {
            domPlace.classList.remove("waiting_box");
            if (oData.servers && oData.servers.length > 0) {
                domPlace.innerHTML = oData.servers.map(server => server.sUrlA).join('<br/>');
            }
            else {
                domPlace.innerHTML = "";
            }
        }
        if (oData.servers && oData.servers.length > 0) {
            const domTestBtn = document.getElementById("test_btn_" + sId);
            if (domTestBtn) {
                domTestBtn.disabled = true;
            }
        }
    }
    catch (oErr) {
        if (oErr && oErr.error) {
            if (oErr.error.data && oErr.error.data.error_str == "needs_custom_gui_auth") {
                try {
                    await StartTwoFactorAuth(oConn);
                    await AccTestWithServList(oConn, obj, sId, domPlace);
                }
                catch {
                    SetDomDisplayAndInnerHtml(domPlace, "", { delClass: "waiting_box" });
                }
            }
            else if (domPlace && oErr.error.message) {
                domPlace.classList.remove("waiting_box");
                domPlace.innerHTML = "<span class='term_error_cell'>" + oErr.error.message + "</span>";
            }
        }
    }
}
async function AccTestWithConnectFs(oConn, obj, sId, domPlace) {
    try {
        const data = await SendRecivePostApiWithRetry("ConnectFS", { "folder_coords": { "conn": obj.conn, "sAcctKeyA": "" } });
        const data2 = await SendRecivePostApiWithRetry("ListDir", { "filesys_handle": data.filesys_handle, "path": obj.sHomePath, "max_items": 1000 });
        HtmlMsgbox(GetLocaleText("Browse_Account_TestSuccess"), "", { class: "short_message" });
        if (domPlace) {
            domPlace.classList.remove("waiting_box");
            let sResults = "";
            if (data2.items && data2.items.length > 0) {
                for (const it of data2.items) {
                    let img = "<span style='display: inline-block; min-width:1.25rem'>&nbsp;</span>";
                    if (it.bIsFolder) {
                        if (it.bIsLink) {
                            img = DynamicSvg.folder_link + "<span style='display: inline-block; min-width:0.25rem'>&nbsp;</span>";
                        }
                        else {
                            img = DynamicSvg.folder + "<span style='display: inline-block; min-width:0.25rem'>&nbsp;</span>";
                        }
                    }
                    let s = it.sDisplayName;
                    if (!s)
                        s = it.sNameA;
                    if (s)
                        sResults += "<div class='line_for_acc_create_dialog'>" + img + s + "</div>";
                }
            }
            if (sResults) {
                domPlace.innerHTML = GetLocaleText("Browse_Account_TestResults") + "<div class='folders_for_acc_create_dialog'>" + sResults + "</div>";
            }
            else {
                domPlace.innerHTML = GetLocaleText("Browse_Account_TestResults") + " " + GetLocaleText("Str_FolderIsEmpty");
            }
            SetStretchEl();
        }
        const domTestBtn = document.getElementById("test_btn_" + sId);
        if (domTestBtn) {
            domTestBtn.disabled = true;
        }
    }
    catch (oErr) {
        if (oErr && oErr.error) {
            if (oErr.error.data && oErr.error.data.error_str == "needs_custom_gui_auth") {
                await StartTwoFactorAuth(oConn);
                await AccTestWithConnectFs(oConn, obj, sId, domPlace);
            }
            else {
                if (oErr.error.message) {
                    if (domPlace) {
                        domPlace.classList.remove("waiting_box");
                        domPlace.innerHTML = "<span class='term_error_cell'>" + oErr.error.message + "</span>";
                    }
                }
            }
        }
    }
}
async function UniversalTest(sId, obj) {
    const domPlace = ChangeWaitBox("test_results_" + sId, true);
    SetUrlA(obj, obj.sFsName);
    SetSameObjFields(obj, obj.conn);
    try {
        if (obj.sPassword) {
            obj.conn.sPasswordEncMasterA = await EncryptStringWithKey(obj.sPassword, oSavedData.key, oSavedData.iv);
        }
        if (obj.sPrivateKey) {
            obj.conn.sPrivateKeyEncMasterA = await EncryptStringWithKey(obj.sPrivateKey, oSavedData.key, oSavedData.iv);
        }
        const oConnAfter = await SetRealURL(obj.conn, obj);
        if (IsFsGST(oConnAfter.sUrlA) && (!IsServAddr(oConnAfter.sUrlA) || oConnAfter.sUrlA.endsWith(":\/\/" + oConnAfter.sUserIdA + ".goodsync"))) {
            AccTestWithServList(oConnAfter, obj, sId, domPlace);
        }
        else {
            AccTestWithConnectFs(oConnAfter, obj, sId, domPlace);
        }
    }
    catch (oErr) {
        CatchErrProcess(oErr, GetLocaleText("Err_AccountCreationError"), { bNoCurrJobName: true });
        SetDomDisplayAndInnerHtml(domPlace, "", { delClass: "waiting_box" });
    }
}
function SetUrlA(obj, sFileSystem) {
    if (!obj.conn)
        return;
    if (obj.bSecureConn && sFileSystem != "ftps://" && sFileSystem != "https://") {
        sFileSystem = sFileSystem.slice(0, -3) + "s://";
    }
    if (IsFsGST(sFileSystem) && !obj.sUrl && obj.sUserIdA && obj.sUserIdA.endsWith("@siber.com")) {
        const sTmp = obj.sUserIdA.replaceAll("@siber.com", "-siber-com");
        obj.sUserEmailA = obj.sUserIdA;
        obj.sUserIdA = sTmp;
        obj.sUrlA = sFileSystem + sTmp + ".goodsync";
        return;
    }
    if ("sUrl" in obj && (typeof obj.sUrl === 'string')) {
        obj.conn.sUrlA = sFileSystem + CutProtocol(obj.sUrl);
    }
    else if (!obj.conn.sUrlA) {
        obj.conn.sUrlA = sFileSystem;
    }
    const url = ParseUrl(obj.conn.sUrlA);
    obj.conn.sUrlA = url.protocol + url.hostname + url.port;
    if (!obj.sHomePath) {
        obj.sHomePath = url.pathname;
    }
    else {
        obj.sHomePath = NormalizePath(obj.sHomePath);
        if (!obj.sHomePath.startsWith("\/")) {
            obj.sHomePath = "\/" + obj.sHomePath;
        }
    }
}
async function CreateNewAccount(oDTE) {
    const oData = oDTE.Branch.fGetData();
    const oCreateAccData = GetAccCreateDialog(GetFieldValWithDrillUp(oDTE.Branch, "sFs"));
    oCreateAccData.js.bottom_box[0].command = "SaveAccount+";
    oCreateAccData.obj.bContServList = oData.bContServList;
    oCreateAccData.obj.bHasNoServAddr = oData.bHasNoServAddr;
    oCreateAccData.obj.bUserIdInHostname = oData.bUserIdInHostname;
    oCreateAccData.obj.bAuthOauth2 = oData.bAuthOauth2;
    oCreateAccData.obj.conn = new CConn;
    if (!oCreateAccData.js.title) {
        alert("For this FS has not created an account form yet");
        return;
    }
    const oCreateAccMenu = CreateFloatMenu(oCreateAccData.js, { width: "550px", height: -80 }, { "obj": oCreateAccData.obj }, { fontSize: "16px", fOnChangeFM: OnChangeBDT, minWidth: "30rem", minHeight: "20rem", icon: oCreateAccData.icon, xArgs: oDTE });
    oCreateAccMenu.promise.then(() => { }).catch(() => { });
}
function CloneFromShowAccount(oMenu) {
    SaveFromShowAccount(oMenu, true);
}
async function SaveFromShowAccount(oMenu, bClone) {
    const jsAccData = oMenu.xArgs.accData;
    if (!jsAccData)
        return;
    const obj = oMenu.jsFloatMenuDescr.obj;
    SetUrlA(obj, obj.sFsName);
    SetSameObjFields(obj, jsAccData.AcctConn);
    jsAccData.HomePath = obj.sHomePath ? obj.sHomePath : "";
    jsAccData.DisplayName = obj.DisplayNameA;
    SetDomDisplayAndInnerHtml("save_btn_" + oMenu.id, null, { bDisable: true, text: null });
    ChangeWaitBox("test_results_" + oMenu.id, true);
    try {
        if (obj.sPassword) {
            obj.conn.sPasswordEncMasterA = await EncryptStringWithKey(obj.sPassword, oSavedData.key, oSavedData.iv);
        }
        if (obj.sPrivateKey) {
            obj.conn.sPrivateKeyEncMasterA = await EncryptStringWithKey(obj.sPrivateKey, oSavedData.key, oSavedData.iv);
        }
        CreateAccRealUrlGetting(obj.conn, jsAccData.HomePath, oMenu.xArgs.bde, obj, { oMenu, jsAccData, bClone });
    }
    catch (oErr) {
        CloseFloatMenu(oMenu);
    }
}
async function SaveAccount(oMenu) {
    const oDTE = oMenu.xArgs;
    if (!oDTE)
        return;
    const domUrl = document.getElementById("require_url_" + oMenu.id);
    if (domUrl && !domUrl.value) {
        domUrl.style.border = "solid 1px red";
        return;
    }
    const domPlace = document.getElementById("test_results_" + oMenu.id);
    SetWaitingBox(domPlace, GetLocaleText("Str_AccountCreating"));
    const obj = oMenu.jsFloatMenuDescr.obj;
    SetUrlA(obj, GetFieldValWithDrillUp(oDTE.Branch, "sFs"));
    SetSameObjFields(obj, obj.conn);
    try {
        await ListAccForExplorerRequest(null, oDTE);
    }
    catch { }
    try {
        if (obj.sPassword) {
            obj.conn.sPasswordEncMasterA = await EncryptStringWithKey(obj.sPassword, oSavedData.key, oSavedData.iv);
        }
        if (obj.sPrivateKey) {
            obj.conn.sPrivateKeyEncMasterA = await EncryptStringWithKey(obj.sPrivateKey, oSavedData.key, oSavedData.iv);
        }
        for (const oAcc of oDTE.Branch.jsBody) {
            if (CompareAcc(obj, oAcc) === 0) {
                ChangeWaitBox("test_results_" + oMenu.id);
                SetDomDisplayAndInnerHtml("save_btn_" + oMenu.id, null, { bEnable: true, text: null });
                HtmlErrBox(GetLocaleText("Str_Msg_CannotCreateAccount", [oAcc.display_name]), GetLocaleText("Title_Error"), { bNoCurrJobName: true });
                return;
            }
        }
        CreateAccRealUrlGetting(obj.conn, obj.sHomePath ? obj.sHomePath : "", oDTE, obj, { oMenu });
    }
    catch {
        CloseFloatMenu(oMenu);
    }
}
function CompareAcc(acc1, acc2) {
    const sHomePath1 = acc1.sHomePath ? acc1.sHomePath.toLowerCase() : "";
    const sHomePath2 = acc2.sHomePath ? acc2.sHomePath.toLowerCase() : "";
    const sUrl1 = acc1.conn.sUrlA.toLowerCase() || "";
    const sUrl2 = acc2.oConn.sUrlA.toLowerCase() || "";
    if (sHomePath1 !== sHomePath2 || sUrl1 !== sUrl2
        || acc1.conn.sPasswordEncMasterA !== acc2.oConn.sPasswordEncMasterA
        || acc1.conn.sPrivateKeyEncMasterA !== acc2.oConn.sPrivateKeyEncMasterA)
        return -1;
    const aExceptions = ["sUrlA"];
    const aDiffs = [];
    for (const key of Object.keys(acc1.conn)) {
        if ((key in acc2.oConn) && acc1.conn[key] !== acc2.oConn[key] && !aExceptions.includes(key)) {
            aDiffs.push(key);
        }
    }
    return aDiffs.length;
}
async function ShowAccount(sFileSystem, jsAccData, oBDE, bClone) {
    const oCreateAccData = GetAccCreateDialog(sFileSystem);
    if (!oCreateAccData.js.title) {
        alert("For this FS has not created an account form yet");
        return;
    }
    oCreateAccData.js.title = oCreateAccData.js.title.replace(/^New /, '');
    if (bClone) {
        oCreateAccData.js.title = "Clone " + oCreateAccData.js.title;
        oCreateAccData.js.bottom_box[0].command = "CloneFromShowAccount+";
    }
    else {
        oCreateAccData.js.bottom_box[0].command = "SaveFromShowAccount+";
    }
    oCreateAccData.obj.conn = jsAccData.AcctConn;
    SetSameObjFields(jsAccData.AcctConn, oCreateAccData.obj);
    if ("sUrl" in oCreateAccData.obj && jsAccData.AcctConn.sUrlA) {
        oCreateAccData.obj.sUrl = jsAccData.AcctConn.sUrlA;
        if (jsAccData.AcctConn.sUrlA.startsWith("ftps://") || jsAccData.AcctConn.sUrlA.startsWith("https://")) {
            oCreateAccData.obj.bSecureConn = true;
        }
    }
    try {
        if (jsAccData.AcctConn.sPasswordEncMasterA) {
            oCreateAccData.obj.sPassword = await DecryptStringWithKey(jsAccData.AcctConn.sPasswordEncMasterA, oSavedData.key, oSavedData.iv);
        }
        if ("sPrivateKey" in oCreateAccData.obj && jsAccData.AcctConn.sPrivateKeyEncMasterA) {
            oCreateAccData.obj.sPrivateKey = await DecryptStringWithKey(jsAccData.AcctConn.sPrivateKeyEncMasterA, oSavedData.key, oSavedData.iv);
        }
        oCreateAccData.obj.sFsName = sFileSystem;
        oCreateAccData.obj.DisplayNameA = jsAccData.DisplayName || GetLocaleText("Str_Empty");
        oCreateAccData.obj.sHomePath = jsAccData.HomePath;
        oCreateAccData.obj.AccKey = jsAccData.Key;
        oCreateAccData.obj.Timestamp = jsAccData.Timestamp;
        oCreateAccData.obj.sUrl = (jsAccData.AcctConn.sUrlA.indexOf(sFileSystem) === 0) ? jsAccData.AcctConn.sUrlA.substring(sFileSystem.length) : jsAccData.AcctConn.sUrlA;
        oCreateAccData.obj.UrlB = jsAccData.AcctConn.sUrlA;
        oCreateAccData.js.cont[0].cont.push({ type: "hidden_group", title: "Account Details", cont: oCreateAccData.add, class: "float_menu_hidden_group_body acc_details_group" });
        const oShowAccMenu = CreateFloatMenu(oCreateAccData.js, { width: "550px", height: -80 }, { "obj": oCreateAccData.obj }, {
            fontSize: "16px",
            fOnChangeFM: OnChangeBDT,
            minWidth: "30rem",
            minHeight: "20rem",
            icon: oCreateAccData.icon,
            xArgs: { accData: jsAccData, bde: oBDE }
        });
        oShowAccMenu.promise.then(() => { }).catch(() => { });
    }
    catch (oErr) {
    }
}
async function DeleteAccount(oBDE) {
    if (IsAccReadOnly(oBDE) || !oBDE.DTP || !oBDE.Branch)
        return;
    const oData = oBDE.Branch.fGetData();
    let sAccName = oData.sUrl + oData.sHomePath;
    if (oData.display_name) {
        sAccName = oData.display_name + " (" + sAccName + ") ";
    }
    try {
        let nTmp = oBDE.DTP.fGetSelRowNum(0);
        await AsyncHtmlConfirm(GetLocaleText("Str_AskDeleteAccount", [sAccName]), "", 1, { sFontSize: "16px", bNoCurrJobName: true });
        await SendRecivePostApiWithRetry("DeleteAccount", { "Key": oData.sAccKey });
        oBDE.Branch.fDeleteSelf();
        oBDE.DTP.fSelTabClean();
        oBDE.DTP.fSelTabPush(nTmp);
        oBDE.DTP.ShowTable();
    }
    catch (oErr) {
        CatchErrProcess(oErr);
    }
}
function OAuth2Connect(sId, obj) {
    if (obj.sUrlA) {
        SetSameObjFields(obj, obj.conn);
        oOAuth2.OAuth2ConnectRequest(obj.conn, sId);
    }
}
function GetAccCreateDialog(sFileSystem) {
    const jsCredentials = {
        title: "", cont: [], bottom_box: [
            { title: "Btn_Save", id: "save_btn", default: true },
            { title: "Btn_Cancel", close: true, },
        ]
    };
    let oCreateAccDialogh = {};
    let aAccDetales = [
        { type: "textfield", title: "Browse_Str_Account_Name", value: "obj['DisplayNameA']", readOnly: true, title_width: "160px", el_class: "acc_delails" },
        { type: "textfield", title: "Browse_Account_Key", value: "obj['AccKey']", readOnly: true, title_width: "160px", el_class: "acc_delails" },
        { type: "textfield", title: "Browse_Account_URL", value: "obj['UrlB']", readOnly: true, title_width: "160px", el_class: "acc_delails" },
        { type: "textfield", title: "Browse_Str_Account_ModTime", value: "obj['Timestamp']", readOnly: true, title_width: "160px", el_class: "acc_delails", time: true },
    ];
    let icon = "";
    switch (sFileSystem) {
        case "afpd://":
        case "smb://":
        case "smbd://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["Net Shares (" + sFileSystem + ")"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Account_ServerAddress", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sUrl']", id: "require_url", non_empty: true },
                            { type: "text", title: "Browse_Account_ShareName", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", id: "require_user_id", non_empty: true, },
                                    { type: "text", title: "Browse_Account_Password", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrl: "", sHomePath: "", sUserIdA: "", sPassword: "" };
                icon = (sFileSystem == "afpd://") ? "fs_sibafp" : (sFileSystem == "smbd://") ? "fs_smbd" : "fs_winnet";
            }
            break;
        case "gstps://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["GoodSync Connect"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_Email", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Account_Password", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "textfield", title: "Browse_Str_DirectGstp", value: "obj['sUrl']", title_width_group: "2" },
                                    { type: "checkbox", title: "Browse_Str_GstpPlainDirect", value: "obj['bGstpPlainDirect']" },
                                    { type: "textfield", title: "Browse_Str_ClientCert", value: "obj['sPrivateKeyPath']", title_width_group: "2" },
                                    { type: "checkbox", title: "Browse_Str_Use_Proxy", value: "obj['bUseProxy']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "", sPassword: "", sUrl: "", sPrivateKeyPath: "", bGstpPlainDirect: false, bUseProxy: true };
                icon = "fs_gstp";
            }
            break;
        case "gstore://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["GoodSync Storage"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_Email", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Account_Password", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "", sPassword: "" };
                icon = "fs_gstp";
            }
            break;
        case "ftps://":
        case "ftp://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["FTP"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_FTP" },
                            { type: "text", title: "Browse_Account_ServerAddress", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sUrl']" },
                            { type: "text", title: "Browse_Account_HomeFolder", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Account_Password", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                    { type: "checkbox", title: "Str_SSL_SecureConnection", value: "obj['bSecureConn']" },
                                ]
                            },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_UTF8_encoding", value: "obj['bEncodeUTF8']" },
                                    { type: "checkbox", title: "Browse_Str_Use_Proxy", value: "obj['bUseProxy']" },
                                    { type: "checkbox", title: "Browse_Str_IgnoreBadCerts", value: "obj['bIgnoreBadCerts']" },
                                    { type: "checkbox", title: "Browse_Str_ActiveMode", value: "obj['bActiveMode']" },
                                    { type: "checkbox", title: "Browse_Str_UseEPSV_FTP", value: "obj['bUseEPSV']" },
                                    { type: "checkbox", title: "Browse_Str_ImplicitMode", value: "obj['bImplicitMode']" },
                                    { type: "checkbox", title: "Browse_Str_UseMDTM_FTP", value: "obj['bUseMDTM']" },
                                    { type: "checkbox", title: "Browse_Str_UseMLSD_FTP", value: "obj['bUseMLSD']" },
                                    { type: "checkbox", title: "Browse_Str_FtpListLa", value: "obj['bUseListLA']" },
                                    { type: "checkbox", title: "Browse_Str_MoveLevelOnly", value: "obj['bMoveLevelOnly']" },
                                    { type: "checkbox", title: "Browse_Str_SessionReuse", value: "obj['bDataConnSessionReuse']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = {
                    sUserIdA: "", sPassword: "", sHomePath: "", sUrl: "", bSecureConn: false,
                    bEncodeUTF8: true, bUseProxy: true, bIgnoreBadCerts: false, bActiveMode: false, bUseEPSV: false, bImplicitMode: false,
                    bUseMDTM: false, bUseMLSD: true, bUseListLA: false, bMoveLevelOnly: false, bDataConnSessionReuse: true
                };
                icon = "fs_sftp";
            }
            break;
        case "sftp://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["SFTP"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_SecureFTP" },
                            { type: "text", title: "Browse_Account_ServerAddress", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sUrl']" },
                            { type: "text", title: "Browse_Account_HomeFolder", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_SecureFTP_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                    { type: "text", title: "Browse_Str_PrivKey", class: "text_above_field" },
                                    { type: "textarea", title: "Browse_Str_PrivKey", value: "obj['sPrivateKey']", id: "private_key" },
                                    { type: "fileload", title: "", command: "LoadTextToTextarea('private_key_' + oMenu.id, text)", value: "obj['sPrivateKey']" },
                                    { type: "text", title: "Str_ClientCertificate", class: "text_above_field" },
                                    { type: "textarea", title: "", value: "obj['sClientCertA']", id: "client_cert" },
                                    { type: "fileload", title: "", command: "LoadTextToTextarea('client_cert_' + oMenu.id, text)", value: "obj['sClientCertA']" },
                                ]
                            },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_Use_Proxy", value: "obj['bUseProxy']" },
                                    { type: "checkbox", title: "Browse_Str_UTF8_encoding", value: "obj['bEncodeUTF8']" },
                                    { type: "checkbox", title: "Browse_Str_IgnoreHostKeys", value: "obj['bIgnoreBadCerts']" },
                                    { type: "checkbox", title: "Browse_Str_DisableStrictKex", value: "obj['bDisableStrictKex']" },
                                    { type: "checkbox", title: "Browse_Str_DisableConveyor", value: "obj['bDisableConveyor']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "", sPassword: "", sPrivateKey: "", sUrl: "", sHomePath: "", sClientCertA: "", bEncodeUTF8: true,
                    bUseProxy: true, bIgnoreBadCerts: false, bDisableStrictKex: false, bDisableConveyor: false };
                icon = "fs_sftp";
            }
            break;
        case "s3s://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["Amazon S3"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_AmazonS3" },
                            { type: "text", title: "Browse_Account_ServerAddress", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sUrl']" },
                            { type: "text", title: "Browse_Account_S3_InitPath_Cap", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Str_AmazonS3_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_AmazonS3_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_HostBasedAddr", value: "obj['bHostBasedAddr']" },
                                    { type: "checkbox", title: "Browse_Str_UsGovCloud", value: "obj['bUsGovCloud']" },
                                    { type: "checkbox", title: "Browse_Str_UseV2signature", value: "obj['bUseV2signature']" },
                                    { type: "droplist", title: "Browse_Str_S3StorageClass", value: "obj['sStorageClassA']", "list": aStorageClass, str: true },
                                    { type: "checkbox", title: "Browse_Str_RequireCheckSum", value: "obj['bRequireCheckSum']", class: "long_label" },
                                    { type: "checkbox", title: "Browse_Str_CacheFileModTime", value: "obj['bCacheFileModTime']" },
                                    { type: "numberfield", title: "Browse_Str_UploadChunksThreads", value: "obj['nUploadChunksThreads']" },
                                    { type: "droplist", title: "Browse_Str_GeoLocation", value: "obj['sGeoLocationA']", "list": aPreferredRegion, str: true },
                                    { type: "textfield", title: "Browse_Str_SpecifyACP", value: "obj['sAccessPolicyA']" },
                                    { type: "checkbox", title: "Browse_Str_ServerEncrypt", value: "obj['bServerSideEncryption']" },
                                    { type: "textfield", title: "Browse_Str_ServerEncrKey", value: "obj['sServerEncrKeyA']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = {
                    sUrl: "s3.amazonaws.com", sHomePath: "", sUserIdA: "", sPassword: "", nUploadChunksThreads: 5, sServerEncrKeyA: "", sAccessPolicyA: "",
                    sStorageClassA: "", sGeoLocationA: "",
                    bHostBasedAddr: true, bUsGovCloud: false, bUseV2signature: false, bRequireCheckSum: false, bCacheFileModTime: false, bServerSideEncryption: false
                };
                icon = "fs_s3";
            }
            break;
        case "gcp://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["Google Cloud Storage"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Tip_GCloudStor", class: "text_above_field" },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "text", title: "Browse_Account_GCP_InitPath_Str", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: "Browse_Account_OAuth_GoogleSignIn" },
                                    { type: "button", img: "google-logo", title: "Browse_Account_OAuth_GoogleSignInBtn", command: "Nothing", value: "obj", id: "connect_btn" },
                                    { type: "text", title: "Browse_Account_GCP_UserID_Str", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_PrivKey", class: "text_above_field" },
                                    { type: "textarea", title: "Browse_Str_PrivKey", value: "obj['sPrivateKey']", id: "private_key" },
                                    { type: "fileload", title: "", command: "LoadTextToTextarea('private_key_' + oMenu.id, text)", value: "obj['sPrivateKey']" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "textfield", title: "Browse_Str_GeoLocation", value: "obj['sGeoLocationA']" },
                                    { type: "numberfield", title: "Browse_Str_UploadChunksThreads", value: "obj['nUploadChunksThreads']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sHomePath: "", sUserIdA: "", sPrivateKey: "", sGeoLocationA: "", nUploadChunksThreads: 5 };
                icon = "fs_gcloud";
            }
            break;
        case "gcs://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["Google Cloud via S3"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_GCloud_S3" },
                            { type: "text", title: "Browse_Account_S3_InitPath_Cap", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Str_GCloud_S3_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_GCloud_S3_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "textfield", title: "Browse_Str_GeoLocation", value: "obj['sGeoLocationA']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sHomePath: "", sUserIdA: "", sPassword: "", sGeoLocationA: "" };
                icon = "fs_gcloud";
            }
            break;
        case "mega://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["MEGA"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_Mega" },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Str_Mega_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_Mega_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "myaccount", sPassword: "", sUrlA: "mega:\/\/g.api.mega.co.nz" };
                icon = "fs_mega";
            }
            break;
        case "azures://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["MS Azure Blobs"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_WindowsAzure" },
                            { type: "text", title: "Browse_Account_S3_InitPath_Cap", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Str_WindowsAzure_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_WindowsAzure_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_UsGovCloud", value: "obj['bUsGovCloud']" },
                                    { type: "droplist", title: "Browse_Str_StorageClass", value: "obj['sStorageClassA']", "list": ["Default", "cold", "archive"], str: true },
                                    { type: "numberfield", title: "Browse_Str_UploadChunksThreads", value: "obj['nUploadChunksThreads']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sHomePath: "", sUrlA: sFileSystem, sUserIdA: "", sPassword: "", sGeoLocationA: "", bUsGovCloud: false, sStorageClassA: "", nUploadChunksThreads: 5 };
                icon = "fs_azure";
            }
            break;
        case "azurefiles://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["MS Azure Files"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_AzureFiles" },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Str_WindowsAzure_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_WindowsAzure_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_UsGovCloud", value: "obj['bUsGovCloud']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "", sPassword: "", bUsGovCloud: false, sUrlA: sFileSystem };
                icon = "fs_azure";
            }
            break;
        case "pcloud://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["pCloud"]);
                jsCredentials.cont = [{ title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_pCloud" },
                            { type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded2", ["pCloud"]) },
                                    { type: "button", img: "fs_pcloud", title: GetLocaleText("Browse_Account_OAuthConnectApp", ["pCloud"]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                                ] },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "numberfield", title: "Browse_Str_UploadChunksThreads", value: "obj['nUploadChunksThreads']" },
                                ] },
                        ] }];
                oCreateAccDialogh = { sUserIdA: "", nUploadChunksThreads: 5, sUrlA: "pcloud:\/\/pcloud.com" };
                icon = "fs_pcloud";
            }
            break;
        case "backblaze://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["Backblaze B2"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_Backblaze" },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Str_Backblaze_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Str_Backblaze_Passwd", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "numberfield", title: "Browse_Str_UploadChunksThreads", value: "obj['nUploadChunksThreads']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "", sPassword: "", nUploadChunksThreads: 5, sUrlA: sFileSystem };
                icon = "fs_backblaze";
            }
            break;
        case "https://":
        case "http://":
            {
                jsCredentials.title = GetLocaleText("Title_NewAccount", ["WebDAV"]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_WebDav" },
                            { type: "text", title: "Browse_Account_ServerAddress", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sUrl']" },
                            { type: "text", title: "Browse_Account_DavRoot", class: "text_above_field" },
                            { type: "textfield", title: "", value: "obj['sHomePath']", optional: true },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Account_Password", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                    { type: "checkbox", title: "Str_SSL_SecureConnection", value: "obj['bSecureConn']" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "textfield", title: "Browse_Str_ClientCert", value: "obj['sPrivateKeyPath']" },
                                    { type: "checkbox", title: "Browse_Str_WinInet", value: "obj['bWinInet']" },
                                    { type: "checkbox", title: "Browse_Str_Use_Proxy", value: "obj['bUseProxy']" },
                                    { type: "checkbox", title: "Browse_Str_UTF8_encoding", value: "obj['bEncodeUTF8']" },
                                    { type: "checkbox", title: "Browse_Str_IgnoreBadCerts", value: "obj['bIgnoreBadCerts']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = {
                    sUrl: "", sHomePath: "", sUserIdA: "", sPassword: "", sPrivateKeyPath: "",
                    bWinInet: false, bSecureConn: false, bUseProxy: true, bEncodeUTF8: true, bIgnoreBadCerts: false
                };
                icon = "fs_dav";
            }
            break;
        case "msgraph://":
            {
                const sName = "OneDrive Office365 SharePoint";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_MsGraph" },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_msgraph", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_Graph_GroupRead", value: "obj['bGraphGroupReadPermissions']" },
                                    { type: "checkbox", title: "Browse_Str_Graph_DirectoryRead", value: "obj['bGraphDirectoryReadPerms']" },
                                    { type: "textfield", title: "Browse_Str_Graph_Tenant", value: "obj['sTenant']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, sTenant: "", bGraphGroupReadPermissions: false, bGraphDirectoryReadPerms: false };
            }
            break;
        case "dropbox://":
            {
                const sName = "Dropbox";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_Dropbox" },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_dropbox", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "numberfield", title: "Browse_Str_UploadChunksThreads", value: "obj['nUploadChunksThreads']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, nUploadChunksThreads: 5 };
            }
            break;
        case "gteamdrive://":
        case "goodrive://":
            {
                let sName = "Google Team Drive";
                let sTip = "Browse_Short_Tip_GTeamDrive";
                if (sFileSystem == "goodrive://") {
                    sName = "Google All Drive";
                    sTip = "Browse_Tip_GAllDrive";
                }
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: sTip },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_gdrive3", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_ExportNativeDocs", value: "obj['bExportNativeDocs']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, bExportNativeDocs: false };
                icon = "fs_gdrive3";
            }
            break;
        case "gdrive://":
            {
                const sName = "Google Drive";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_GDrive" },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_gdrive3", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, bExportNativeDocs: false };
            }
            break;
        case "gphotos://":
            {
                const sName = "Google Photos";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_GPhotos" },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_gphotos", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, bExportNativeDocs: false };
            }
            break;
        case "gdocs3://":
            {
                const sName = "Google Docs";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_GNativeDocs" },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_gdrive3", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, bExportNativeDocs: false };
            }
            break;
        case "box://":
            {
                const sName = "Box.com";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: "Browse_Short_Tip_BoxCom" },
                            {
                                type: "option_group", title: "Browse_Account_Authorization", cont: [
                                    { type: "text", title: GetLocaleText("Browse_Account_OAuthNeeded", [sName]), class: "small_text" },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", img: "fs_boxcom", title: GetLocaleText("Browse_Account_OAuthConnectApp", [sName]), command: "OAuth2Connect", value: "obj", id: "connect_btn" },
                            { type: "place", title: "Test Results", id: "test_results", class: "test_account_results" },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUrlA: sFileSystem, bExportNativeDocs: false };
            }
            break;
        case "icloud://":
        case "iphotos://":
            {
                let sFsName = (sFileSystem == "iphotos://") ? "Apple iCloud Drive" : "Apple iCloud Drive";
                let sFsTip = (sFileSystem == "iphotos://") ? "Browse_Short_Tip_ICloudPhotos" : "Browse_Short_Tip_ICloudDrive";
                jsCredentials.title = GetLocaleText("Title_NewAccount", [sFsName]);
                jsCredentials.cont = [
                    {
                        title: "", cont: [
                            { type: "text", title: sFsTip },
                            {
                                type: "option_group", title: "Browse_Account_Credentials", cont: [
                                    { type: "text", title: "Browse_Account_UserID", class: "text_above_field" },
                                    { type: "textfield", title: "", value: "obj['sUserIdA']", },
                                    { type: "text", title: "Browse_Account_Password", class: "text_above_field" },
                                    { type: "password", title: "", value: "obj['sPassword']", },
                                ]
                            },
                            { type: "row", "h": "15px", cont: [] },
                            { type: "button", title: "test", command: "UniversalTest", value: "obj", id: "test_btn", class: "float_right flt_menu_btn" },
                            { type: "place", title: "Test Results", id: "test_results" },
                            {
                                type: "hidden_group", title: "Advanced Options", cont: [
                                    { type: "checkbox", title: "Browse_Str_CnICloud", value: "obj['bCnICloud']" },
                                ]
                            },
                        ]
                    }
                ];
                oCreateAccDialogh = { sUserIdA: "", sPassword: "", bCnICloud: false };
                icon = (sFileSystem == "iphotos://") ? "fs_iphotos" : "fs_icloud";
            }
            break;
    }
    oCreateAccDialogh.sFsName = sFileSystem;
    return { js: jsCredentials, obj: oCreateAccDialogh, add: aAccDetales, icon: icon };
}
function AddFillUrlForGSTx(account_data) {
    if (!account_data)
        return "";
    switch (account_data.sUrlA.toLowerCase()) {
        case 'gstp://':
        case 'gstps://':
        case 'gstore://': return account_data.sUrlA + account_data.sUserIdA + ".goodsync";
        default: return account_data.sUrlA;
    }
}
function GetServerName(sUrlA, sServerName, sUserName, bForBmkKey) {
    let nPos1 = sServerName.indexOf("://");
    if (nPos1 < 0)
        nPos1 = 0;
    else
        nPos1 += 3;
    if (IsFsGST(sUrlA)) {
        let nPos2 = sServerName.indexOf("." + sUserName + ".");
        if (nPos2 >= 0)
            return sServerName.slice(nPos1, nPos2);
        else if (bForBmkKey)
            return "";
    }
    else if (sUrlA.toLowerCase().startsWith("file://")) {
        return "";
    }
    let nPos3 = sServerName.indexOf("/", nPos1 + 1);
    if (nPos3 > 0) {
        return sServerName.slice(nPos1, nPos3);
    }
    return sServerName.slice(nPos1);
}
function IsFsGST(sUrlA) {
    if (!sUrlA)
        return false;
    sUrlA = sUrlA.toLowerCase();
    return /^(gstp:\/\/|gstps:\/\/|gstore:\/\/)+/.test(sUrlA);
}
function GetGstServerName(sUrl, sUserId) {
    if (!sUrl || !sUserId)
        return "";
    const arr = sUrl.split("." + sUserId);
    if (arr.length < 2)
        return "";
    const arr2 = arr[0].split("://");
    if (arr2.length < 2)
        return "";
    return arr2[1];
}
function IsServAddr(sUrlA) {
    try {
        const oUrl = ParseUrl(sUrlA);
        return !!oUrl.hostname;
    }
    catch (err) {
        return false;
    }
}
function IsFs(xAddArgs, aFs) {
    return aFs.includes(GetFieldValWithDrillUp(xAddArgs.Branch, "sFs"));
}
function IsAccHaveServerList(xAddArgs) {
    return xAddArgs.Branch.fGetData().bContServList;
}
function IsFile(xAddArgs) {
    return xAddArgs.Branch.fGetData().bIsFile;
}
function IsAccReadOnly(xAddArgs) {
    return xAddArgs.Branch.fGetData().bAccReadOnly;
}
function CanBeJobSide(dwAbilities, Branch, bItsDst) {
    const bNoFolders = (dwAbilities & GS_AB_CANNOT_CREATE_FOLDERS) !== 0;
    const bNoFiles = (dwAbilities & GS_AB_CANNOT_HAVE_FILES) !== 0;
    if (!bNoFolders && !bNoFiles)
        return true;
    if (bItsDst || !Branch || !Branch.pParent)
        return false;
    while (Branch.pParent && Branch.pParent.pParent) {
        Branch = Branch.pParent;
    }
    const oData = Branch.fGetData();
    const bIsICloudPhotos = oData.sName == "icloud://" || oData.sName == "iphotos://";
    return oData.bReadOnlyFS && !bIsICloudPhotos;
}
function CanFolderToBeCreateIn(dwAbilities) {
    return (dwAbilities & GS_AB_CANNOT_CREATE_FOLDERS) === 0;
}
function CanFileToBeCreateIn(dwAbilities) {
    return (dwAbilities & GS_AB_CANNOT_HAVE_FILES) === 0;
}
function CanCreateFolder(xAddArgs) {
    return xAddArgs.Branch.fGetData().bCanCreateFolder;
}
function IsItBrowser() {
    return location.pathname.includes("WebGSExplorer.html");
}
function IsBmEncOrZip(Opts) {
    if (Opts.bEncryptBodies || Opts.bEncryptPaths)
        return "enc";
    if (Opts.nCompressType > 1)
        return "zip";
    return "";
}
function IsIntoEncOrZip(oBr) {
    const oData = oBr.fGetData();
    if (oData.oBookmark && IsBmEncOrZip(oData.oBookmark.Opts)
        || oData.oBookmarkAcc && IsBmEncOrZip(oData.oBookmarkAcc.Opts)) {
        return true;
    }
    if (!oBr.pParent)
        return false;
    return IsIntoEncOrZip(oBr.pParent);
}
function SaveExplorerData(sUrl, sKey, bUrl2) {
    if (bUrl2) {
        oSavedData.url2 = sUrl;
        oSavedData.accKey2 = sKey;
    }
    else {
        oSavedData.url1 = sUrl;
        oSavedData.accKey1 = sKey;
    }
    localStorage.setItem("oSavedData", JSON.stringify(oSavedData));
}
function OpenJobSideInBrowser(nInd, oJobInList) {
    OpenInBrowser({ nInd, oJobInList });
}
async function OpenInBrowser(xAddArgs, text) {
    const urlWithPath = new URL(location.origin + location.pathname + '/static/WebGSExplorer.html');
    if (xAddArgs.Branch) {
        const oData = xAddArgs.Branch.fGetData();
        if (oData && oData.fGetPathAndName && oData.fGetUrl) {
            SaveExplorerData(oData.fGetUrl() + oData.fGetPathAndName(xAddArgs.Branch, true), oData.fGetAccKey(xAddArgs.Branch));
        }
    }
    else if (xAddArgs.oJobInList) {
        const oJobInList = xAddArgs.oJobInList;
        SaveExplorerData(xAddArgs.nInd ? oJobInList.right_url : oJobInList.left_url, oJobInList.oSideCoords[xAddArgs.nInd].sAcctKeyA);
    }
    else if (text) {
        const oJobInList = glob.GetJobInList(sCurrJob);
        if (oJobInList) {
            const ind = (text == "Cmd_OpenLFolder") ? 0 : 1;
            SaveExplorerData(oJobInList.oSideCoords[ind].conn.sUrlA + "/" + xAddArgs.oTreeRow._branch_.fGetPathStr("/"), oJobInList.oSideCoords[ind].sAcctKeyA);
        }
    }
    oSavedData.url2 = "";
    oSavedData.accKey2 = "";
    oSavedData.eExplorerMode = 'med_icon_mode';
    oSavedData.server = urlWithPath.href.split("/session-")[0];
    localStorage.setItem("oSavedData", JSON.stringify(oSavedData));
    window.open(urlWithPath, '_blank');
}
async function CreateFolder(oBDE) {
    let oData = oBDE.Branch.fGetData();
    if (oBDE.DTP && oBDE.DTP.oParentDTP && oBDE.DTP.oParentBr) {
        const oBr = oBDE.DTP.oParentBr.fFindEl(oData.display_name, "display_name");
        if (!oBr)
            return;
        oBDE = { Branch: oBr, DTP: oBDE.DTP.oParentDTP };
        oData = oBr.fGetData();
    }
    try {
        const jsFolderNameEnter = {
            "title": "Explorer_OpNewFolder",
            "bottom_box": [
                { "title": "Str_CreateNewFolder", "close": true, command: "create", default: true },
                { "title": "Cancel", "close": true },
            ], cont: [
                {
                    "title": "", cont: [
                        { type: "row", "h": "5px", cont: [] },
                        { type: "textfield", "title": "Str_FolderName", "value": "sNewFolderName" },
                        { type: "row", "h": "5px", cont: [] },
                    ]
                }
            ]
        };
        const obj = { sNewFolderName: "" };
        const fm = CreateFloatMenu(jsFolderNameEnter, { width: "600px", top: "30%" }, obj, { fontSize: "calc(var(--base-font-size) * 1.25);" });
        await fm.promise;
        if (!obj.sNewFolderName)
            return;
        obj.sNewFolderName = obj.sNewFolderName.replaceAll("\\", "/");
        let sName = obj.sNewFolderName.startsWith("/") ? obj.sNewFolderName : "/" + obj.sNewFolderName;
        let sPath = oData.fGetPathAndName(oBDE.Branch, true);
        const oBM = GetBM(oBDE.Branch);
        if (oBM) {
            sPath = sPath.slice(oBM.BmkKey.length);
        }
        await MakeFolderRequest(sPath + sName, oBDE, obj.sNewFolderName);
    }
    catch (oErr) {
        CatchErrProcess(oErr, "MakeFolderRequest", { bNoCurrJobName: true });
    }
}
async function RenameAccount(oBDE) {
    const aData = oBDE.Branch.fGetData();
    const sKey = aData.fGetAccKey();
    const sOldName = aData.display_name;
    if (sKey) {
        const jsFolderNameEnter = {
            title: "Str_ChangeAccountName",
            bottom_box: [
                { title: "Btn_Change", close: true, command: "create", default: true },
                { title: "Cancel", close: true },
            ], cont: [
                {
                    title: "", cont: [
                        { type: "text", "title": GetLocaleText("Str_OldName", [sOldName]) },
                        { type: "row", "h": "5px", cont: [] },
                        { type: "textfield", title: "Str_NewName", value: "sNewName" },
                        { type: "row", h: "5px", cont: [] },
                    ]
                }
            ]
        };
        const obj = { sNewName: "" };
        const fm = CreateFloatMenu(jsFolderNameEnter, { width: "600px", top: "30%" }, obj, { fontSize: "calc(var(--base-font-size) * 1.25);" });
        try {
            await fm.promise;
            if (!obj.sNewName || obj.sNewName == sOldName)
                return;
            const sDisplayName = (await SendRecivePostApiWithRetry("RenameAccount", { "Key": sKey, "DisplayName": obj.sNewName })).DisplayName;
            oBDE.Branch.fSetData("display_name", sDisplayName);
            oBDE.DTP.ShowRows();
        }
        catch (oErr) {
            CatchErrProcess(oErr, "", { bNoCurrJobName: true, sErrType: "RenameAccount" });
        }
    }
}
const FOLDER_OPTIONS_PSWD_MIN_LEN = 8;
async function ConfirmAndWaitFolderClean(oMenu) {
    await AsyncHtmlConfirm(GetLocaleText("Str_AskREmoveAllFromFolder", [oMenu.jsMenuPart.meta.sSidePath]), GetLocaleText("Btn_Encrypt_EmptyFolder"), eMyConfDefBtn.cancel);
    const jsWaitingFileListBox = {
        title: "Info_FolderContentsRemoving", bottom_box: [], cont: [
            {
                title: "", cont: [
                    { type: "text", title: "<b>Path: " + oMenu.jsMenuPart.meta.sSidePath + "</b></br>" },
                    { type: "place", title: "- Start of clearing -", id: "spop_state", class: "nowrap_nooverflow_ellipse" },
                ]
            }
        ]
    };
    const oWaitingBox = CreateFloatMenu(jsWaitingFileListBox, { width: "40%", top: "30%" }, null);
    oWaitingBox.promise.then(() => { }).catch(() => { });
    return oWaitingBox.oMenu;
}
async function RemoveFolderContFromExplorer(oMenu) {
    if (!oMenu.jsMenuPart || !oMenu.jsMenuPart.meta || !oMenu.jsMenuPart.meta.sFsHandle) {
        HtmlMsgbox(GetLocaleText("Err_SmthgWntWrongWthFolderClean"), GetLocaleText("Ttl_ErrMsg"));
        return;
    }
    let oWaitBoxMenu = null;
    try {
        oWaitBoxMenu = await ConfirmAndWaitFolderClean(oMenu);
        const domPlace = document.getElementById("spop_state_" + oWaitBoxMenu.id);
        domPlace.innerText = "- Start of clearing -";
        const oConn = CopyObject(oMenu.jsMenuPart.meta.oFC.conn);
        let aPath = oConn.sUrlA.split("\/");
        if (aPath.length < 2) {
            HtmlMsgbox(GetLocaleText("Err_SmthgWntWrongWthFolderClean"), GetLocaleText("Ttl_ErrMsg"));
            throw null;
        }
        const sFolderName = "\/" + aPath[aPath.length - 1];
        aPath.splice(aPath.length - 1);
        oConn.sUrlA = aPath.join("\/");
        const oParams = { folder_coords: { conn: oConn, sAcctKeyA: oMenu.jsMenuPart.meta.oFC.sAcctKeyA }, path_list: [sFolderName], };
        let oAns = await SendRecivePostApiWithRetry("DeleteFiles", oParams);
        const sHandle = oAns.fop_handle;
        while (oAns.state <= 1 && !oWaitBoxMenu.bSelfDeleted) {
            await new Promise(resolve => setTimeout(resolve, 1000));
            if (oWaitBoxMenu.bSelfDeleted && oAns.state <= 1) {
                oAns = await SendRecivePostApiWithRetry("CancelFileOp", { "fop_handle": sHandle });
            }
            else {
                oAns = await SendRecivePostApiWithRetry("GetFileOpStatus", { "fop_handle": sHandle });
            }
        }
        if (oAns.state != 2) {
            if (oAns.state == 4) {
                HtmlMsgbox(GetLocaleText("Err_SmthgWntWrongWthFolderClean"), GetLocaleText("Ttl_ErrMsg"));
            }
            throw null;
        }
        await SendRecivePostApiWithRetry("MakeFolder", { "filesys_handle": oMenu.jsMenuPart.meta.sFsHandle, "path": oMenu.jsMenuPart.meta.sSidePath });
        HtmlMsgbox(GetLocaleText("Msg_Encr_Test_Empty"), GetLocaleText("Str_Success"));
        if (oMenu.jsMenuPart.meta.oBDE) {
            RefreshBrowseBranch("", oMenu.jsMenuPart.meta.oBDE);
        }
    }
    catch (oErr) {
        CatchErrProcess(oErr);
    }
    CloseFloatMenu(oWaitBoxMenu);
}
function RemoveFolderCont(oMenu) {
    const sLockCurrJob = sCurrJob;
    HtmlConfirm(GetLocaleText("Str_AskREmoveAllFromFolder", [oMenu.jsMenuPart.meta.sSidePath]), GetLocaleText("Btn_Encrypt_EmptyFolder"), eMyConfDefBtn.cancel)
        .then(async () => {
        const jsWaitingFileListBox = {
            title: "Info_FolderContentsRemoving", bottom_box: [], cont: [
                {
                    title: "", cont: [
                        { type: "text", title: "<b>Path: " + oMenu.jsMenuPart.meta.sSidePath + "</b></br>" },
                        { type: "place", title: "- Start of clearing -", id: "spop_state", class: "nowrap_nooverflow_ellipse" },
                    ]
                }
            ]
        };
        const oWaitingBox = CreateFloatMenu(jsWaitingFileListBox, { width: "40%", top: "30%" }, null);
        pGlobalWaitinBox = oWaitingBox.oMenu;
        oWaitingBox.promise.then(() => { }).catch(() => { });
        const domPlace = document.getElementById("spop_state_" + oWaitingBox.oMenu.id);
        domPlace.innerText = "- Start of clearing -";
        try {
            await SendRecivePostApiWithRetry("StartSpecOp", {
                "job_name": sLockCurrJob,
                "spop_type": (oMenu.jsMenuPart.meta.eSideNum ? 7 : 6)
            }, { "domMenu": pGlobalWaitinBox });
            const oJobInList = glob.GetJobInList(sLockCurrJob);
            if (oJobInList) {
                oJobInList.pMenu = oMenu;
            }
        }
        catch (catchData) {
            if (!pGlobalWaitinBox || pGlobalWaitinBox.bSelfDeleted)
                return;
            CloseFloatMenu(pGlobalWaitinBox);
            if (catchData && catchData.error && catchData.error.message) {
                HtmlErrBox(catchData.error.message, "Error folder clearing");
            }
        }
    }).catch(() => {
        if (pGlobalWaitinBox) {
            CloseFloatMenu(pGlobalWaitinBox);
            pGlobalWaitinBox = null;
        }
    });
}
async function FolderOptionsRequest(eSideNum) {
    const oSideCoords = jsCurrJobOptions.side_coords[eSideNum];
    const sKey = oSideCoords.sAcctKeyA;
    try {
        const aAcc = await SendRecivePostApiWithRetry("ListAccounts", { "start_from": sKey, "max_items": 1 });
        if (aAcc.accounts.length > 0) {
            const aBookmarks = aAcc.accounts[0].UnnamedBookmarks;
            const oBMin = aBookmarks.find(it => it.BmkKey == oSideCoords.sServerDirA);
            const oBM = new CBookmark;
            if (oBMin) {
                oBM.sServerDirA = oBMin.BmkKey;
                oBM.Opts = oBMin.Opts;
            }
            else {
                oBM.sServerDirA = oSideCoords.sServerDirA;
            }
            oBM.sAcctKeyA = sKey;
            OpenFolderOptionSets(oBM, aAcc.accounts[0].AcctConn.sUrlA + oBM.sServerDirA, eSideNum, oSideCoords);
        }
    }
    catch (oErr) {
        if (oErr) {
            SendRecivePostApiCatch(oErr, "Accounts '" + sKey + "' err: ", {});
        }
    }
}
async function OpenFolderOptionSets(oBM, sUrlA, eSideNum, oFC, oBDE) {
    const js = {
        title: eSideNum === 0 ? "Cmd_LeftSideOpts" : eSideNum > 0 ? "Cmd_RightSideOpts" : (GetLocaleText("Btn_FolderOptions") + ": " + sUrlA),
        bottom_box: [
            { title: "Save", close: true, command: "save", id: "save_btn", default: true },
            { title: "Cancel", close: true, }
        ], cont: [{ title: "", cont: [] }]
    };
    if (sUrlA.startsWith("file://") || sUrlA.startsWith("smb://") || IsFsGST(sUrlA)) {
        js.cont[0].cont.push({
            type: "option_group", title: "Str_Side_FileSystem", cont: [
                { type: "checkbox", title: "Browse_Str_PreferCompressed", value: "bPreferCompressed", },
                { type: "checkbox", title: "Browse_Str_PreferEncrypted", value: "bPreferEncrypted", },
                { type: "checkbox", title: "Browse_Str_FatLike", value: "bFatLike", },
            ]
        });
    }
    js.cont[0].cont.push({
        type: "option_group", title: "Str_Side_Encryption", cont: [
            {
                type: "droplist", title: "Str_Side_Settings_Title", lineHeight: "2", value: "nCompressType", id: "side_enc",
                "list": ["Str_Side_Settings_Mode_NotUse", "Chk_Encrypt_FileAll", "Str_Side_Settings_Mode_CompEncr"]
            },
            {
                type: "droplist", title: "Str_Side_Cipher_Title", value: "nCipherType", id: "enc_method",
                "list": ["Str_Side_Cipher_NotUse", "ZipCrypto", "AES-256"], control: { hide: "ID#[side_enc] !== 2" }
            },
            {
                type: "column", title: "EncMetod", control: { hide: "ID#[side_enc] === 0 || ID#[side_enc] === 2 && ID#[enc_method] === 0" }, cont: [
                    { type: "password", title: "Chk_Encrypt_Password", value: "sRawPasswd", title_width: "200px", id: "psw1", same: { id: "psw2", disable: ["save_btn"] } },
                    { type: "password", title: "Chk_Encrypt_Password2", value: "sRepPasswd", title_width: "200px", id: "psw2", same: { id: "psw1", disable: ["save_btn"] } },
                ]
            },
            { type: "checkbox", title: "Chk_Encrypt_FilePaths", value: "bEncryptPaths", bNoControl: true, control: { hide: "ID#[side_enc] !== 2 || ID#[enc_method] === 0" } },
            { type: "row", "h": "0.5rem", cont: [] },
            {
                type: "row", control: { hide: "ID#[side_enc] === 0" }, cont: [
                    { type: "button", title: "Btn_Encrypt_Test", command: "BtnEncryptTest(jsFloatMenuDescr, oMenu)", control: { disable: "(ID#[side_enc] !== 2 || ID#[enc_method] === 0) && ID#[side_enc] !== 1" } },
                    { type: "button", title: "Btn_Encrypt_EmptyFolder", command: (eSideNum === -2) ? "RemoveFolderContFromExplorer(oMenu)" : "RemoveFolderCont(oMenu)" },
                ]
            },
            { type: "row", "h": "0.5rem", cont: [] },
        ]
    }, { type: "checkbox", title: "Chk_NoGsData_Side", value: "bNoGsData", });
    js.meta = {};
    js.meta.sSidePath = oBM.sServerDirA || oBM.BmkKey;
    js.meta.eSideNum = eSideNum;
    js.meta.oFC = oFC;
    js.meta.oBDE = oBDE;
    if (oBDE && oBDE.Branch) {
        const oData = oBDE.Branch.fGetData();
        js.meta.sFsHandle = await oFsHandle.get(oBDE.Branch);
    }
    const oFO = CopyObject(oBM.Opts);
    if (oFO.bEncryptBodies && oFO.bEncryptPaths && oFO.nCipherType === 0 && oFO.nCompressType === 0) {
        oFO.nCompressType = 1;
    }
    try {
        if (oFO.sEncryptionPasswdEncMasterA) {
            const sDecryptPass = await DecryptStringWithKey(oFO.sEncryptionPasswdEncMasterA, oSavedData.key, oSavedData.iv);
            oFO.sRawPasswd = sDecryptPass;
            oFO.sRepPasswd = sDecryptPass;
        }
        else {
            oFO.sRawPasswd = "";
            oFO.sRepPasswd = "";
        }
        const menu = CreateFloatMenu(js, { width: '650px', top: "20%" }, oFO, { minHeight: "20rem", minWidth: "30rem", bCurrJobName: eSideNum >= 0 });
        await menu.promise;
        ProcessingChangeFolderOptions(oFO, oBM, sUrlA, eSideNum, oBDE);
    }
    catch (oErr) {
        CatchErrProcess(oErr);
    }
}
async function ProcessingChangeFolderOptions(oFO, oBM, sUrlA, eSide, oBDE) {
    if (oFO.nCompressType == 0 || oFO.nCompressType == 2 && oFO.nCipherType == 0) {
        oFO.sRawPasswd = "";
        oFO.sEncryptionPasswdEncMasterA = "";
    }
    const oCmp = CompareObjs(oFO, oBM.Opts, [], eSidePriority.right);
    if (Object.keys(oCmp).length === 0)
        return;
    if (oFO.nCompressType == 1 || oFO.nCompressType == 2 && oFO.nCipherType != 0) {
        if (!oFO.sRawPasswd) {
            HtmlMsgbox(GetLocaleText("Err_RequirePassword"), "<span style='color:red'>Error</span>");
            throw null;
        }
        else if (oFO.sRawPasswd !== oFO.sRepPasswd) {
            HtmlMsgbox(GetLocaleText("Err_NotMatchPassword"), "<span style='color:red'>Error</span>");
            throw null;
        }
        else if (oFO.sRawPasswd.length < FOLDER_OPTIONS_PSWD_MIN_LEN) {
            HtmlMsgbox(GetLocaleText("Err_ShortPassword", ["" + FOLDER_OPTIONS_PSWD_MIN_LEN]), "<span style='color:red'>Error</span>");
            throw null;
        }
    }
    let sOptChangeQuestions = "";
    if (oFO.bNoGsData !== oBM.Opts.bNoGsData && !oBDE) {
        sOptChangeQuestions = (oFO.bNoGsData ? GetLocaleText("Warn_KeepGsData") : GetLocaleText("Warn_MoveGsData")) + "<p>";
    }
    oFO.bEncryptBodies = oFO.nCompressType === 1;
    oFO.bEncryptPaths = oFO.nCompressType === 1 || oFO.nCompressType === 2 && oFO.bEncryptPaths;
    if (oFO.nCompressType === 1) {
        oFO.nCompressType = 0;
        oFO.nCipherType = 0;
    }
    oBM.BmkKey = oBM.sServerDirA || oBM.BmkKey;
    oBM.sServerDirA = oBM.BmkKey;
    try {
        let sEncryptPass = "";
        if (oFO.sRawPasswd) {
            sEncryptPass = await EncryptStringWithKey(oFO.sRawPasswd, oSavedData.key, oSavedData.iv);
            if (oBM.Opts.sEncryptionPasswdEncMasterA != sEncryptPass && !oBDE) {
                sOptChangeQuestions += GetLocaleText("Warn_Encrypt_Changed", [sUrlA], { bBold: true, sQuotes: "'" });
            }
        }
        else {
            if (oBM.Opts.sEncryptionPasswdEncMasterA) {
                sOptChangeQuestions += GetLocaleText("Warn_Encrypt_Changed", [sUrlA], { bBold: true, sQuotes: "'" });
            }
        }
        if (sOptChangeQuestions) {
            await AsyncHtmlConfirm(sOptChangeQuestions, "", eMyConfDefBtn.cancel);
            if (eSide >= 0) {
                await DeleteGsDataFolderRequest(sCurrJob, eSide == 0);
            }
        }
        SetSameObjFields(oFO, oBM.Opts);
        if (sEncryptPass) {
            oBM.Opts.sEncryptionPasswdEncMasterA = sEncryptPass;
        }
        const respData = await SendRecivePostApiWithRetry("SetUnnamedBookmark", { "bookmark_data": oBM });
        if (oBDE && oBDE.Branch && respData.bookmark_data) {
            const oData = oBDE.Branch.fGetData();
            oData.oBookmark = respData.bookmark_data;
            const sType = IsBmEncOrZip(respData.bookmark_data.Opts);
            if (sType == "zip") {
                oData.icon = "gs-zip";
            }
            else if (sType == "enc") {
                oData.icon = "folder-enc";
            }
            else {
                oData.icon = "folder";
                delete oData.oBookmark;
                delete oData.sFsHandle;
                delete oData.bIgnoreBookmark;
            }
            AddBookmarkToAcc(respData.bookmark_data, oBDE.Branch);
            if ((oSavedData.eExplorerMode == 'detal_mode' || oSavedData.eExplorerMode == 'med_icon_mode') && oBDE.Branch.pParent) {
                await RefreshBrowseBranch(sType ? "Encrypt" : "Normal", { DTP: oBDE.DTP, Branch: oBDE.Branch.pParent });
                if (oBDE.DTP && oBDE.DTP.oFolderContTable) {
                    const oTarget = oBDE.DTP.oFolderContTable.root.fFindEl(oData.display_name, "display_name");
                    if (oTarget) {
                        oTarget.fMarkAndShow(oBDE.DTP.oFolderContTable);
                    }
                }
            }
            else {
                await RefreshBrowseBranch(sType ? "Encrypt" : "Normal", oBDE);
            }
        }
    }
    catch (oErr) {
        CatchErrProcess(oErr);
    }
}
function GetAccWithCreds(oConn, oDTP, sUser) {
    const url = ParseUrl(oConn.sUrlA);
    const oFs = oDTP.root.fFindEl(url.protocol);
    if (oFs) {
        const aAcc = oFs.jsBody;
        let sAccKey = "";
        let pCommAcc;
        for (const oAcc of aAcc) {
            if (oAcc.sUrl == url.protocol) {
                pCommAcc = oAcc;
                continue;
            }
            if (IsFsGST(oConn.sUrlA) && url.hostname.endsWith(oAcc.oConn.sUserIdA + ".goodsync") ||
                (sUser && oAcc.oConn.sUserEmailA.startsWith(sUser) || !sUser) &&
                    DoJobPathsContainsOneAnother(oAcc.sUrl + oAcc.sHomePath, oConn.sUrlA, true)) {
                sAccKey = oAcc.sAccKey;
                break;
            }
        }
        if (sAccKey) {
            return oFs.fFindEl(sAccKey);
        }
        if (pCommAcc) {
            return oFs.fFindEl(pCommAcc.sAccKey);
        }
    }
}
function ExploreTableRowClick(oTableBranch, oBDP, pNewUrl, sAddPath, domSaveBtn) {
    const ret = SetNewUrlForExplorer(oTableBranch, pNewUrl, sAddPath);
    if (oBDP.fIsThisChoiceGood && !oBDP.fIsThisChoiceGood(oTableBranch.fGetData())) {
        if (domSaveBtn) {
            domSaveBtn.disabled = true;
        }
        if (pNewUrl) {
            pNewUrl.classList.add("err_in_field");
            if (oBDP.sErrHint)
                pNewUrl.title = GetLocaleText(oBDP.sErrHint);
        }
    }
    else {
        if (domSaveBtn) {
            domSaveBtn.disabled = false;
        }
        if (pNewUrl) {
            pNewUrl.classList.remove("err_in_field");
            pNewUrl.title = "";
        }
    }
    return ret;
}
function CreateBrowserTree(aFileSystems, oBDP, add = {}) {
    const oDTP = new CDynTabProp();
    oDTP.aHead = jsFloatMenuTableHeads.ExploreTableHead;
    oDTP.bIsTree = true;
    oDTP.nLevelNotSort = 1;
    oDTP.sSortCol = "display_name";
    oDTP.bNeedSort = true;
    oDTP.bStriped = true;
    oDTP.fKeyDown = (e) => {
        if (e.code == "Delete") {
            e.preventDefault();
            FsOperations('DeleteFiles', { oDTP1: oDTP });
        }
    };
    if (oBDP.bWOFiles) {
        oDTP.fFiltr = Nothing;
    }
    if (add.fBackspace) {
        oDTP.fBackspace = add.fBackspace;
    }
    oDTP.root.fAddDataArr(aFileSystems, {
        sPathFieldName: "plain_url",
        oFunc: {
            fOpenFolder: async function (oBranch, oDTPx, bDontOpen) {
                await ListAccForExplorerRequest(null, { Branch: oBranch, DTP: oDTPx, domErr: add.pResume }, bDontOpen);
            },
            fRightBtn: function (e, Branch, oDTPx) {
                TableRowClick(oDTPx, Branch, true);
                DropMenuWithFavor(e, Branch, oDTPx, jsBrowseDialogFsMenu);
            },
        },
        fDataProcessor: SetFsBranch,
        bNoSelectWithShiftOrCtrl: true,
    });
    return oDTP;
}
async function BrowseDialogForSideUrlChange(aFileSystems, oBDP) {
    if (!oBDP.ind) {
        oBDP.ind = 0;
    }
    if (!oBDP.sUrl2) {
        oBDP.sUrl2 = "";
    }
    const oResume = {};
    const oDTP = CreateBrowserTree(aFileSystems, oBDP, oResume);
    oDTP.bOnlyOneSelRow = true;
    oDTP.bHide = oBDP.bWOFiles;
    let sUrlForChange = "";
    if (oBDP.oIFDD && oBDP.oIFDD.conn.sUrlA) {
        sUrlForChange = oBDP.oIFDD.conn.sUrlA;
    }
    const obj = { oDTP: oDTP, sUrlForChange: GetPathForShow(sUrlForChange), sUrl2: GetPathForShow(oBDP.sUrl2) };
    if (oBDP.bSetPath) {
        if (oBDP.sDialogTitile) {
            jsFloatMenu["ChoiceFileDialog"].title = oBDP.sDialogTitile;
        }
        glob.oBrowseDialog = CreateFloatMenu(jsFloatMenu["ChoiceFileDialog"], { width: "calc(100% - 40px)", left: "20px", top: "10%", height: -85 }, obj, { bNoResize: true });
        const pNewUrl = document.getElementById("UrlForChange_" + glob.oBrowseDialog.oMenu.id);
        const domSaveBtn = document.getElementById("Btn_Select_" + glob.oBrowseDialog.oMenu.id);
        if (pNewUrl && "value" in pNewUrl) {
            pNewUrl.fKeyDown = (e) => ExplorerUrlEnter(e, pNewUrl, oBDP, oDTP);
        }
        oDTP.fRowClick = function (oTableBranch) {
            ExploreTableRowClick(oTableBranch, oBDP, pNewUrl, "", domSaveBtn);
        };
        glob.oBrowseDialog.promise.then(() => {
            if (oBDP.domUrl) {
                oBDP.domUrl.value = obj.sUrlForChange;
                oBDP.domUrl.dispatchEvent(new Event('input'));
            }
        }).catch(() => { }).finally(() => {
            DisconnectAllFs();
            glob.oBrowseDialog = undefined;
        });
    }
    else {
        oDTP.root.fGetData().bItsDst = oBDP.sDirection === "arrow-left-right"
            || oBDP.sDirection === "move-left" && oBDP.ind === 1
            || oBDP.sDirection === "move-right" && oBDP.ind === 0;
        const oUrlStr = { type: "row", cont: [] };
        if (oBDP.ind) {
            oUrlStr.cont = [
                { type: "text", title: GetPathForShow(oBDP.sUrl2), class: "side_for_browse", htmlTitle: GetPathForShow(oBDP.sUrl2) },
                { type: "img1", value: oBDP.sDirection, class: "img_for_browse", h: 24 },
                { type: "textfield", value: "sUrlForChange", el_class: "url_for_change", id: "UrlForChange", put: "SearchPathInBrowseDialog" },
            ];
        }
        else {
            oUrlStr.cont = [
                { type: "textfield", value: "sUrlForChange", el_class: "url_for_change", id: "UrlForChange", put: "SearchPathInBrowseDialog" },
                { type: "img1", value: oBDP.sDirection, class: "img_for_browse", h: 24 },
                { type: "text", title: GetPathForShow(oBDP.sUrl2), class: "side_for_browse", htmlTitle: GetPathForShow(oBDP.sUrl2) },
            ];
        }
        const js = {
            title: "", "bottom_box": [
                { title: "Btn_Select", close: true, command: "save", "default": true, id: "Btn_Select" },
                { title: "Btn_Cancel", close: true },
            ], cont: [
                {
                    title: "", cont: [
                        oUrlStr,
                        { type: "place", title: "", id: "resume" },
                        { type: "table", title: "", dynTable: "oDTP", h: "100%", class: "browse_dialog_table" },
                    ]
                }
            ]
        };
        const oFCO = new CForChangeOptions;
        glob.oBrowseDialog = CreateFloatMenu(js, { width: "calc(100% - 40px)", left: "20px", top: "10%", height: -85 }, obj, { bNoResize: true });
        oFCO.bIsDialogOpen = true;
        oDTP.oMeta.oMenu = glob.oBrowseDialog.oMenu;
        const domSaveBtn = document.getElementById("Btn_Select_" + glob.oBrowseDialog.oMenu.id);
        oResume.pResume = document.getElementById("resume_" + glob.oBrowseDialog.oMenu.id) || undefined;
        const pNewUrl = document.getElementById("UrlForChange_" + glob.oBrowseDialog.oMenu.id);
        if (pNewUrl && "value" in pNewUrl) {
            pNewUrl.fKeyDown = (e) => ExplorerUrlEnter(e, pNewUrl, oBDP, oDTP);
        }
        oDTP.fRowClick = async function (oTableBranch, bMouseClick) {
            if (oResume.pResume) {
                BlockAndWaitCreate(oResume.pResume, "side_choice_wait", 3);
            }
            const sNewUrl = await SetNewJobUrl({ DTP: oDTP, Branch: oTableBranch }, oBDP.ind, oBDP.sUrl2, oFCO, { dom: pNewUrl, domResume: oResume.pResume, domSaveBtn, bMouseClick });
            DeleteAllClassEl("block_and_wait");
            if (sNewUrl) {
                obj.sUrlForChange = sNewUrl;
            }
        };
        if (domSaveBtn) {
            domSaveBtn.disabled = false;
        }
        glob.oBrowseDialog.promise.then((oData) => {
            if (oData.data.sUrlForChange != GetPathForShow(sUrlForChange)) {
                if (!sUrlForChange.trim() || sUrlForChange == "&nbsp;") {
                    JobOptionsForChangeRequest(oFCO);
                }
                else {
                    let qsn = GetLocaleText("Browse_SureAboutChange1") + "<p><b>" + GetLocaleText("Str_CurrentFolder") + ":</b><br/>"
                        + GetPathForShow(sUrlForChange) + "<p><b>" + GetLocaleText("Explorer_OpNewFolder") + ":</b><br/>" + GetPathForShow(oData.data.sUrlForChange)
                        + "<p>" + GetLocaleText("Browse_SureAboutChange") + "<p><b>" + GetLocaleText("Qsn_WhatWouldYouLikeToDo") + "</b>";
                    HtmlConfirm(qsn, oBDP.ind ? "Str_ChangeRightSyncFolder" : "Str_ChangeLeftSyncFolder", eMyConfDefBtn.ok, { ok: "Btn_SaveChange" }).then(() => {
                        JobOptionsForChangeRequest(oFCO, true);
                    }).catch(() => { });
                }
            }
        }).catch(() => { }).finally(() => {
            DisconnectAllFs();
            oFCO.bIsDialogOpen = false;
            glob.oBrowseDialog = undefined;
        });
    }
    if (oBDP.oIFDD) {
        let nEndOfNameFs = oBDP.oIFDD.conn.sUrlA.indexOf("://");
        if (nEndOfNameFs > 0) {
            let sFsUrl = oBDP.oIFDD.conn.sUrlA.substring(0, nEndOfNameFs + 3);
            let oTargetRow = oDTP.aDeploedTable.find(item => GetFieldValWithDrillUp(item._branch_, "sFs") == sFsUrl);
            if (oTargetRow) {
                await ListAccForExplorerRequest(oBDP.oIFDD, { Branch: oTargetRow._branch_, DTP: oDTP, domErr: oResume.pResume });
            }
            else {
                const oFs = aFileSystems.find(it => it.plain_url == sFsUrl);
                if (oFs) {
                    bShowHiddenFs = true;
                    const oNewFs = oDTP.root.fAddData(oFs, {
                        sPathFieldName: "plain_url",
                        oFunc: {
                            fOpenFolder: async function (oBranch, oDTPx) {
                                await ListAccForExplorerRequest(null, { Branch: oBranch, DTP: oDTPx, domErr: oResume.pResume });
                            },
                            fRightBtn: async function (e, Branch, oDTPx) {
                                DropMenuWithFavor(e, Branch, oDTPx, jsBrowseDialogFsMenu);
                                await TableRowClick(oDTPx, Branch);
                            }
                        },
                        fDataProcessor: SetFsBranch
                    });
                    bShowHiddenFs = false;
                    oDTP.ShowTable();
                    await ListAccForExplorerRequest(oBDP.oIFDD, { Branch: oNewFs, DTP: oDTP, domErr: oResume.pResume });
                }
            }
        }
    }
}
async function ExplorerUrlProc(sNewUrl, oBDP, oDTP) {
    let sPath = NormalizePath(sNewUrl);
    if (!sPath)
        return;
    const url = ParseUrl(sPath);
    if (url.protocol == "file://") {
        sPath = "file:///" + url.pathname;
    }
    let oNewConn = null;
    if (oBDP.oIFDD && oBDP.oIFDD.conn) {
        oNewConn = CopyObject(oBDP.oIFDD.conn);
    }
    else {
        oNewConn = new CConn;
    }
    oNewConn.sUrlA = sPath.replace(url.user, "");
    const oFS = oDTP.root.fFindEl(url.protocol);
    if (oFS) {
        await ListAccForExplorerRequest({ "conn": oNewConn, key: oBDP.sKey1 || "", user: url.user }, { Branch: oFS, DTP: oDTP });
    }
    else {
        try {
            const aFs = (await SendRecivePostApiWithRetry("ListFileSystems", { url: url.protocol })).file_systems;
            if (!aFs || aFs.length < 1) {
                throw null;
            }
            aFs[0].properties.hide_in_fs_list = "0";
            oDTP.root.fAddDataArr(aFs, {
                sPathFieldName: "plain_url",
                oFunc: {
                    fOpenFolder: async function (Branch, DTP) {
                        await ListAccForExplorerRequest(null, { Branch, DTP, domErr: null });
                    },
                    fRightBtn: async function (e, Branch, oDTPx) {
                        DropMenuWithFavor(e, Branch, oDTPx, jsBrowseDialogFsMenu);
                        await TableRowClick(oDTPx, Branch, true);
                    }
                },
                bNoSelectWithShiftOrCtrl: true,
                fDataProcessor: SetFsBranch
            });
            oDTP.ShowTable();
            const oFS1 = oDTP.root.fFindEl(url.protocol);
            if (!oFS1) {
                throw null;
            }
            await ListAccForExplorerRequest({ "conn": oNewConn, key: oBDP.sKey1 || "", user: url.user }, { Branch: oFS1, DTP: oDTP });
        }
        catch {
            if (!bItIsWebExplorer) {
                ErrorMsgShow(GetLocaleText("Err_FileSystemDidntFind", [url.protocol], { bBold: true }), { sTitle: "Err_FileSystemSearchingError", eGoal: "msgbox" });
            }
        }
    }
}
function ExplorerUrlEnter(e, pNewUrl, oBDP, oDTP) {
    if (e.code == "Enter") {
        e.preventDefault();
        ExplorerUrlProc(pNewUrl.value, oBDP, oDTP);
    }
}
function SetFolderOptFromJobDetails(xArgs) {
    CreateBrowsDialogWindows(xArgs.nInd, xArgs.oJobInList);
}
function SetFolderOptFromExplorer(oBDE) {
    if (!oBDE.Branch)
        return;
    let oData = oBDE.Branch.fGetData();
    if (oBDE.DTP && oBDE.DTP.oParentDTP && oBDE.DTP.oParentBr) {
        const oBr = oBDE.DTP.oParentBr.fFindEl(oData.display_name, "display_name");
        if (!oBr)
            return;
        oBDE = { Branch: oBr, DTP: oBDE.DTP.oParentDTP };
        oData = oBr.fGetData();
    }
    const oFC = new CFolderCoords;
    oFC.conn = CopyObject(oData.oConn);
    const sPath = oData.fGetPathAndName(oBDE.Branch);
    oFC.conn.sUrlA += sPath;
    oFC.sAcctKeyA = oData.fGetAccKey();
    const sServerName = GetServerName(oFC.conn.sUrlA, oFC.conn.sUrlA, oFC.conn.sUserIdA, true);
    let sBmkKey = sPath;
    if (IsFsGST(oFC.conn.sUrlA)) {
        sBmkKey = sServerName + sPath;
    }
    else {
        const sTmpUrl = oFC.conn.sUrlA.toLowerCase();
        if ((sTmpUrl.startsWith("smbd://") || sTmpUrl.startsWith("smb://")
            || sTmpUrl.startsWith("afp://") || sTmpUrl.startsWith("afpd://")
            || sTmpUrl.startsWith("wd://")) && !oFC.conn.sUserIdA || sTmpUrl.startsWith("mtp://")) {
            sBmkKey = sServerName + sPath;
        }
    }
    let oBM = GetBM(oBDE.Branch);
    if (!oBM) {
        let bmBranch = oBDE.Branch.fFindEl("", "aBookmarks", "up");
        if (bmBranch) {
            const oBmArrData = bmBranch.fGetData();
            oBM = oBmArrData.aBookmarks.find(it => it.BmkKey == sBmkKey || it.sServerDirA == sBmkKey);
        }
    }
    if (!oBM) {
        oBM = new CBookmark(sBmkKey, oFC.sAcctKeyA);
    }
    else {
        oBM.sAcctKeyA = oFC.sAcctKeyA;
    }
    OpenFolderOptionSets(oBM, oFC.conn.sUrlA, -2, oFC, oBDE);
}
function GetAndShowOptionsFromJobDetails(xArgs) {
    GetAndShowJobOptions(xArgs.nInd ? 'Title_JobRightSide' : 'Title_JobLeftSide');
}
function CopyPathToClipboard(xArgs) {
    navigator.clipboard.writeText(xArgs.nInd ? xArgs.oJobInList.right_url : xArgs.oJobInList.left_url);
}
const CHK_ENC_FILE_MAX_SIZE = 0x400000;
const CHK_ENC_FILE_ARR_LEN = 2;
const CHK_ENC_NAME_ARR_LEN = 6;
const CHK_ENC_MAX_REQ_NUM = 20;
const CHK_ENC_MAX_PAGE_NUM = 100;
const CHK_ENC_PREFER_FOLDER = "_gsdata_";
const CHK_ENC_PREFER_NAME1 = "_gsdata_/_file_state_v4._gs";
const CHK_ENC_PREFER_NAME2 = "_gsdata_/_recycled_db._gs";
const GS_CANNOT_DECRYPT_NAME_PREFIX = "#cannot-decrypt-name#";
async function BtnEncryptTest(oFO, oMenu, bSetUBM) {
    if (oFO.nCompressType == 0 || oFO.nCompressType == 2 && oFO.nCipherType == 0) {
        return;
    }
    if (!oFO.sRawPasswd) {
        HtmlErrBox(GetLocaleText("Err_RequirePassword"), "Password error");
        return;
    }
    else if (oFO.sRawPasswd !== oFO.sRepPasswd && !bSetUBM) {
        HtmlErrBox(GetLocaleText("Err_NotMatchPassword"), "Password error");
        return;
    }
    else if (oFO.sRawPasswd.length < FOLDER_OPTIONS_PSWD_MIN_LEN) {
        HtmlErrBox(GetLocaleText("Err_ShortPassword", ["" + FOLDER_OPTIONS_PSWD_MIN_LEN]), "Password error");
        return;
    }
    let oTmpBM;
    if (bSetUBM) {
        oTmpBM = new CFolderCoords;
        oTmpBM.opts = new COpts;
        oTmpBM.conn = CopyObject(oMenu.jsMenuPart.meta.conn);
        oTmpBM.conn.sUrlA += oMenu.jsMenuPart.meta.sServerDirA;
        oTmpBM.sServerDirA = oMenu.jsMenuPart.meta.sServerDirA;
        oTmpBM.sAcctKeyA = oMenu.jsMenuPart.meta.sAcctKeyA;
    }
    else {
        oTmpBM = CopyObject(oMenu.jsMenuPart.meta.oFC);
        if (!oTmpBM.opts) {
            oTmpBM.opts = new COpts;
        }
    }
    SetSameObjFields(oFO, oTmpBM.opts);
    oTmpBM.opts.bEncryptBodies = oTmpBM.opts.nCompressType === 1;
    oTmpBM.opts.bEncryptPaths = oTmpBM.opts.nCompressType === 1 || oTmpBM.opts.nCompressType === 2 && oTmpBM.opts.bEncryptPaths;
    if (oTmpBM.opts.nCompressType === 1) {
        oTmpBM.opts.nCompressType = 0;
        oTmpBM.opts.nCipherType = 0;
    }
    const oWaitingMenu = CreateWaitingBox("Info_EncTest");
    try {
        oTmpBM.opts.sEncryptionPasswdEncMasterA = await EncryptStringWithKey(oFO.sRawPasswd, oSavedData.key, oSavedData.iv);
        const oConnectFsResult = await ConnectFsRequestPromise(oTmpBM);
        const aErrMsg = [];
        const aPathArr = [CHK_ENC_PREFER_NAME1, CHK_ENC_PREFER_NAME2];
        for (const sFile of aPathArr) {
            try {
                await OpenFile(oConnectFsResult.filesys_handle, sFile);
            }
            catch (oErr) {
                if (oErr && oErr.error && oErr.error.data && oErr.error.data.error_str == "local_err" && oErr.error.message) {
                    aErrMsg.push(sFile + ": " + oErr.error.message);
                }
            }
            await CloseFileRequest(oConnectFsResult.filesys_handle, true);
        }
        const oListDirResult = await ListDirRequestPromise(oConnectFsResult.filesys_handle, "", "", CHK_ENC_MAX_PAGE_NUM);
        if (oListDirResult.items.length == 0) {
            CloseFloatMenu(oWaitingMenu);
            HtmlMsgbox(GetLocaleText("Msg_Encr_Test_Empty"), oTmpBM.sServerDirA, { bNoCurrJobName: true, inner_icon: "properties" });
        }
        else {
            const aEncNames = [];
            await EncryptTest(oTmpBM.sServerDirA, oConnectFsResult.filesys_handle, 0, oListDirResult, "", aErrMsg, aEncNames, [], [], oWaitingMenu);
            if (!oWaitingMenu || oWaitingMenu.bSelfDeleted) {
                throw null;
            }
            CloseFloatMenu(oWaitingMenu);
            if (aErrMsg.length > 3) {
                HtmlErrBox(aErrMsg.join("<br>"), GetLocaleText("Err_FailDecrFileName"), { bNoCurrJobName: true });
            }
            else {
                if (aEncNames.length > 5) {
                    aEncNames[5] = "...";
                }
                HtmlMsgbox(GetLocaleText("Msg_Encr_Test_List_Encrypted") + "<br>" + aEncNames.join("<br>"), oTmpBM.sServerDirA, { bNoCurrJobName: true, inner_icon: "properties" });
            }
        }
    }
    catch (oErr) {
        CloseFloatMenu(oWaitingMenu);
        CatchErrProcess(oErr, "Title_CopyItems", { bNoCurrJobName: true });
        if (oErr && oErr.error && oErr.error.message) {
            HtmlErrBox(oErr.error.message, GetLocaleText("Err_FailDecrFileName"), { bNoCurrJobName: true });
        }
    }
}
async function EncryptTest(sFolderPath, sFsHandle, nReqNum, oData, sPath, aErrMsg, aEncNames, aPathsForEncBodys, aFolders, oWaitingMenu) {
    const aFData = oData.items;
    for (const oItem of aFData) {
        if (!oWaitingMenu || oWaitingMenu.bSelfDeleted)
            return;
        const sfPathAndName = sPath ? sPath.substring(1) + "\/" + oItem.sNameA : oItem.sNameA;
        if (oItem.sNameA.startsWith(GS_CANNOT_DECRYPT_NAME_PREFIX)) {
            if (oItem.bIsFolder) {
                aEncNames.push(sfPathAndName + "\/");
            }
            else {
                aEncNames.push(sfPathAndName);
            }
            continue;
        }
        if (oItem.bIsFile) {
            const nSize = Number(oItem.size);
            if (nSize < CHK_ENC_FILE_MAX_SIZE) {
                if (aPathsForEncBodys.length < CHK_ENC_FILE_ARR_LEN) {
                    aPathsForEncBodys.push(sfPathAndName);
                }
            }
            if (aEncNames.length < CHK_ENC_NAME_ARR_LEN) {
                aEncNames.push(sfPathAndName);
            }
        }
        else if (oItem.bIsFolder) {
            aEncNames.push(sfPathAndName + "\/");
            if (oItem.sNameA.endsWith(CHK_ENC_PREFER_FOLDER)) {
                aFolders.splice(0, 0, sPath + "\/" + oItem.sNameA);
            }
            else {
                aFolders.push(sPath + "\/" + oItem.sNameA);
            }
        }
        if (aPathsForEncBodys.length >= CHK_ENC_FILE_ARR_LEN && aEncNames.length >= CHK_ENC_NAME_ARR_LEN)
            break;
    }
    if (nReqNum >= CHK_ENC_MAX_REQ_NUM
        || aPathsForEncBodys.length >= CHK_ENC_FILE_ARR_LEN && aEncNames.length >= CHK_ENC_NAME_ARR_LEN
        || !oData.next_page_token && aFolders.length == 0) {
        for (const sFile of aPathsForEncBodys) {
            if (!oWaitingMenu || oWaitingMenu.bSelfDeleted)
                return;
            try {
                await OpenFile(sFsHandle, sFile);
            }
            catch (oErr) {
                if (oErr && oErr.error && oErr.error.data && oErr.error.data.error_str == "local_err" && oErr.error.message) {
                    aErrMsg.push(sFile + ": " + oErr.error.message);
                }
            }
            await CloseFileRequest(sFsHandle);
        }
        return;
    }
    let nextPageTok = "";
    let sTmpPath = sPath;
    if (oData.next_page_token) {
        nextPageTok = oData.next_page_token;
    }
    else {
        if (aFolders[0] == "/_gsdata_") {
            if (aFolders.length == 1) {
                return;
            }
            aFolders.splice(0, 1);
        }
        sTmpPath = aFolders[0];
        aFolders.splice(0, 1);
    }
    try {
        const oListDirResult = await ListDirRequestPromise(sFsHandle, sTmpPath, nextPageTok, CHK_ENC_MAX_PAGE_NUM);
        await EncryptTest(sFolderPath, sFsHandle, nReqNum + 1, oListDirResult, sTmpPath, aErrMsg, aEncNames, aPathsForEncBodys, aFolders, oWaitingMenu);
    }
    catch (oErr) {
        if (oErr && oErr.error && oErr.error.message) {
            aErrMsg.push(oErr.error.message + " in folder " + sTmpPath);
        }
    }
}
function openPopup(url, windowName, width, height) {
    const left = window.screenX + (window.outerWidth - width) / 2;
    const top = window.screenY + (window.outerHeight - height) / 2;
    const windowFeatures = `width=${width},height=${height},left=${left},top=${top},resizable,scrollbars`;
    const popup = window.open(url, windowName, windowFeatures);
    if (!popup) {
        HtmlErrBox(GetLocaleText("Err_PopupAuthPageBlocked"), GetLocaleText("Err_AuthErr"));
        return false;
    }
    return true;
}
function NormalizePath(s) {
    s = s.replaceAll("\\", "\/");
    while (s.startsWith("\/")) {
        s = s.slice(1);
    }
    if (s.toLowerCase() == "file:/" || s.toLowerCase() == "file://" || s.toLowerCase() == "file:///") {
        return "file://";
    }
    if (s.endsWith("://")) {
        return s;
    }
    while (s.endsWith("\/")) {
        s = s.slice(0, -1);
    }
    return s;
}
function DoJobPathsContainsOneAnother(left, right, bLeftInRight) {
    if (!left || !right)
        return false;
    left = NormalizePath(left).toUpperCase();
    right = NormalizePath(right).toUpperCase();
    const aLeft = left.split("\/");
    const aRight = right.split("\/");
    if (bLeftInRight) {
        if (aLeft.length > aRight.length)
            return false;
        for (let i = 0; i < aLeft.length; i++) {
            if (aLeft[i] != aRight[i])
                return false;
        }
    }
    else {
        for (let i = 0; i < aLeft.length && i < aRight.length; i++) {
            if (aLeft[i] != aRight[i])
                return false;
        }
    }
    return true;
}
function SearchPathInBrowseDialog(x, value, obj, sFieldName) {
    eval("obj." + sFieldName + " = '" + value + "';");
}
class COAuth2 {
    constructor() {
        this.sSessionHandle = "";
        this.sAuthFormId = "";
    }
    async CheckOAuthState() {
        if (!this.sSessionHandle || !this.sAuthFormId)
            return;
        if (!document.getElementById(this.sAuthFormId)) {
            this.sSessionHandle = "";
            return;
        }
        try {
            const oAns = await SendRecivePostApiWithRetry("GetOAuthState", { session_handle: this.sSessionHandle }, { bDontRetry: true });
            if ((+oAns.state) > 1) {
                this.sSessionHandle = "";
                if (+oAns.state == 2) {
                    const oDialog = this.GetDialog();
                    if (oDialog && oDialog.jsFloatMenuDescr && oDialog.jsFloatMenuDescr.obj && oDialog.jsFloatMenuDescr.obj.oAccData) {
                        const oAccData = oDialog.jsFloatMenuDescr.obj.oAccData;
                        oAccData.AcctConn = oAns.result_conn;
                        CreateAccountRequest(oAns.result_conn, oDialog.jsFloatMenuDescr.obj.oAccData.HomePath, oDialog.jsFloatMenuDescr.obj.oBDE, { jsAccData: oDialog.jsFloatMenuDescr.obj.oAccData, oMenu: oDialog });
                    }
                    else {
                        this.SetConnForCreateAccount(oAns.result_conn);
                    }
                }
                else {
                    this.sSessionHandle = "";
                    HtmlErrBox(oAns.error, GetLocaleText("Err_AuthErr"));
                }
            }
            else {
                setTimeout(() => {
                    this.CheckOAuthState();
                }, 1000);
            }
        }
        catch { }
    }
    SetConnForCreateAccount(oConn) {
        if (!this.sAuthFormId)
            return;
        const oDialog = document.getElementById(this.sAuthFormId);
        if (!oDialog)
            return;
        oConn.bGraphGroupReadPermissions = oDialog.jsFloatMenuDescr.obj.bGraphGroupReadPermissions;
        oConn.bGraphDirectoryReadPerms = oDialog.jsFloatMenuDescr.obj.bGraphDirectoryReadPerms;
        if (oDialog.jsFloatMenuDescr.obj.sTenant) {
            oConn.sGeoLocationA = 'tenant:' + oDialog.jsFloatMenuDescr.obj.sTenant;
        }
        if ((oDialog.jsFloatMenuDescr.obj.sFsName === 'pcloud://') && oConn.sRefreshTokenEncMasterA) {
            oDialog.jsFloatMenuDescr.obj.sUserIdA = oConn.sUserIdA;
        }
        oDialog.jsFloatMenuDescr.obj.conn = oConn;
        const domPlace = document.getElementById("test_results_" + this.sAuthFormId);
        if (domPlace) {
            domPlace.innerHTML = GetLocaleText("Str_Success");
            domPlace.classList.add("oauth_success");
        }
        this.sAuthFormId = "";
    }
    GetDialog() {
        return document.getElementById(this.sAuthFormId);
    }
    async OAuth2ConnectRequest(oConn, sId) {
        try {
            this.sAuthFormId = sId;
            const jsData = await SendRecivePostApiWithRetry("StartOAuth", { conn: oConn });
            if (jsData.consent_url) {
                const ok = openPopup(jsData.consent_url, "windowName: string", 600, 600);
                if (ok) {
                    this.sSessionHandle = jsData.session_handle;
                }
            }
            setTimeout(() => {
                this.CheckOAuthState();
            }, 1000);
        }
        catch { }
    }
}
const oOAuth2 = new COAuth2;
async function SmtpTest(oMenu) {
    const aEmptyFilds = [];
    let oWaitingMenu = null;
    try {
        const SmtpPar = oMenu.jsFloatMenuDescr.CProgramOptionsGlobal.m_SmtpServer;
        if (SmtpPar.m_OAuthProvider === 0) {
            if (!SmtpPar.m_sHostA) {
                aEmptyFilds.push(GetLocaleText("Str_SMTP_Host"));
            }
            if (!SmtpPar.m_sUserIdA) {
                aEmptyFilds.push(GetLocaleText("Str_SMTP_UserID"));
            }
            if (!oMenu.jsFloatMenuDescr.sPassword) {
                aEmptyFilds.push(GetLocaleText("Str_SMTP_Passwd"));
            }
            if (!SmtpPar.m_sSenderStrA) {
                aEmptyFilds.push(GetLocaleText("Str_SMTP_SenderEmail"));
            }
        }
        else {
            if (!SmtpPar.m_sOAuthUserIdA) {
                aEmptyFilds.push(GetLocaleText("Err_NotOAuthSignIn"));
            }
        }
        if (aEmptyFilds.length > 0) {
            HtmlErrBox(GetLocaleText("Err_ErrSendSMTP") + "- " + aEmptyFilds.join("<br>- "), "SMTP test");
            return;
        }
        SmtpPar.m_bUseOAuth2 = SmtpPar.m_OAuthProvider != 0;
        oWaitingMenu = CreateWaitingBox("Str_TestEmaiIsSending");
        SmtpPar.m_sPasswordEncMasterA = await EncryptStringWithKey(oMenu.jsFloatMenuDescr.sPassword, oSavedData.key, oSavedData.iv);
        const oUserData = oMenu.jsFloatMenuDescr.JobServerUserInformation;
        await SendRecivePostApiWithRetry("SendEMail", {
            settings: SmtpPar,
            subject: "Test e-mail",
            body: "Test Body",
            to: oUserData.email,
            to_name: oUserData.display_name
        });
        if (oWaitingMenu && !oWaitingMenu.bSelfDeleted) {
            CloseFloatMenu(oWaitingMenu);
            HtmlMsgbox(GetLocaleText("Str_EmaiTestSuccess") + oUserData.email, "SMTP test", { bNoCurrJobName: true, inner_icon: "success" });
        }
    }
    catch (oErr) {
        if (oErr) {
            if (oErr.error && oErr.error.message && oWaitingMenu && !oWaitingMenu.bSelfDeleted) {
                HtmlErrBox(oErr.error.message, "SMTP test", { bNoCurrJobName: true });
            }
            else if (oErr.message) {
                ErrorMsgShow(oErr.message, { eGoal: "msgbox", sErrType: "ListFileSystems:" });
            }
        }
        CloseFloatMenu(oWaitingMenu);
    }
}
async function SetProgramPaths(oMenu, id) {
    const domUrl = document.getElementById(id + "_" + oMenu.id);
    let sUrl = "";
    if (domUrl) {
        sUrl = domUrl.value;
        if (!sUrl.startsWith("\/") && !sUrl.startsWith("\\")) {
            sUrl = "\/" + sUrl;
        }
        sUrl = "file://" + domUrl.value;
        sUrl = sUrl.replaceAll("\\", "\/");
    }
    try {
        const jsData = await SendRecivePostApiWithRetry("ListFileSystems", { url: "file://" });
        const conn = new CConn;
        conn.sUrlA = sUrl;
        const oBDC = { bSetPath: true, oIFDD: { conn }, domUrl: domUrl };
        switch (id) {
            case 'mirror_folder_url':
                {
                    oBDC.bWOFiles = true;
                    oBDC.fIsThisChoiceGood = IsGoodForMirror;
                    oBDC.sErrHint = "Err_MirrorMustBeFolder";
                    oBDC.sDialogTitile = "Str_MirrorFolder";
                }
                break;
            case "log_folder_url":
                {
                    oBDC.bWOFiles = true;
                    oBDC.fIsThisChoiceGood = IsGoodForMirror;
                    oBDC.sErrHint = "Err_MirrorMustBeFolder";
                    oBDC.sDialogTitile = "Str_LogFolderGlobal";
                }
                break;
            default: {
                oBDC.bWOFiles = false;
                oBDC.fIsThisChoiceGood = IsGoodForCompareProgram;
                oBDC.sErrHint = "Err_CompareProgramCantBeFolder";
                oBDC.sDialogTitile = "Str_CompareProg";
            }
        }
        BrowseDialogForSideUrlChange(jsData.file_systems, oBDC);
    }
    catch (oErr) {
        CatchErrProcess(oErr, "FreeSpaceRequest:", { bNoCurrJobName: true });
    }
}
function IsGoodForCompareProgram(obj) {
    try {
        if (obj.bIsFile)
            return true;
    }
    catch {
        return false;
    }
    return false;
}
function IsGoodForMirror(obj) {
    try {
        if (obj.sName && !obj.bIsFile)
            return true;
    }
    catch {
        return false;
    }
    return false;
}
function CallRowDropMenu(sFieldName, oDepBr, oDTP, cell) {
    const rect = cell.getBoundingClientRect();
    DeleteAllDropMenu();
    let jsMenu = jsBrowseDialogFsMenu;
    if (oDepBr._level_ === 1) {
        jsMenu = jsBrowseDialogAccMenu;
        oUpOrDownData.oBranch = oDepBr._branch_;
        oUpOrDownData.oDTP = oDTP;
    }
    else if (oDepBr._level_ && oDepBr._level_ > 1) {
        const oData = oDepBr._branch_.fGetData();
        oUpOrDownData.oBranch = oDepBr._branch_;
        oUpOrDownData.oDTP = oDTP;
        if (oData.bIsServer) {
            jsMenu = jsBrowseDialogServerMenu;
        }
        else if (oData.bIsFile) {
            jsMenu = jsBrowseDialogFileMenu;
        }
        else {
            jsMenu = jsBrowseDialogFolderMenu;
        }
    }
    DropMenuWithFavor({ clientX: rect.left, clientY: rect.bottom, target: cell }, oDepBr._branch_, oDTP, jsMenu);
}
function SetBmTableFields(aBookmarks) {
    const aBm = [];
    for (const bm of aBookmarks) {
        const eEncOrZip = IsBmEncOrZip(bm.Opts);
        aBm.push({
            BmkKey: bm.BmkKey || bm.sServerDirA,
            bm_icon: (eEncOrZip == "enc") ? "bm-enc" : (eEncOrZip == "zip") ? "bm-zip" : "bm-stroke",
            Timestamp: bm.Timestamp,
            edit: "edit",
            delete: "delete",
            pBm: bm
        });
    }
    return aBm;
}
function BookmarkListTable(oBDE) {
    if (!oBDE.Branch)
        return;
    const oData = oBDE.Branch.fGetData();
    if (!oData.aBookmarks || oData.aBookmarks.length <= 0)
        return;
    const oDTP = new CDynTabProp;
    oDTP.bIsTree = false;
    oDTP.bOnlyOneSelRow = true;
    oDTP.bStriped = true;
    oDTP.aHead = [
        { field_name: "bm_icon", col_name: "&nbsp;", img: true, w: "30px" },
        { field_name: "BmkKey", col_name: "Str_Folder", auto_ext: 40, class: "flex100" },
        { field_name: "Timestamp", col_name: "Browse_Str_Account_ModTime", time: true, class: "short_label" },
        { field_name: "edit", col_name: "&nbsp;", img: true, button: "BmActButton", w: "40px" },
        { field_name: "delete", col_name: "&nbsp;", img: true, button: "BmActButton", w: "40px" },
    ];
    oDTP.root.fAddDataArr(SetBmTableFields(oData.aBookmarks));
    oDTP.oMeta.sAccKey = oData.sAccKey || oData.fGetAccKey(oBDE.Branch);
    oDTP.oMeta.oConn = oData.oConn;
    oDTP.oMeta.aBookmarks = oData.aBookmarks;
    oDTP.oMeta.sHomePath = oData.sHomePath;
    oDTP.oParentDTP = oBDE.DTP;
    const jsBmBox = {
        title: GetLocaleText("Title_Favorites", [oData.display_name]), bottom_box: [], cont: [
            {
                title: "", cont: [
                    { type: "text", title: "Explorer_UnnamedBmkList" },
                    { type: "table", title: "", dynTable: "oDTP", h: "100%", class: "browse_dialog_table" },
                ]
            }
        ]
    };
    const fm = CreateFloatMenu(jsBmBox, { width: "50%", height: -50 }, { oDTP });
    fm.promise.then(() => { }).catch(() => { });
    oDTP.fDblclick = (oBr) => {
        CloseFloatMenu(fm.oMenu);
        ExplorerUrlProc(oData.oConn.sUrlA + oBr.fGetData().BmkKey, { sKey1: oDTP.oMeta.sAccKey }, oBDE.DTP);
    };
}
async function BmActButton(sFieldName, oBranch, oDTP) {
    const oData = oBranch._branch_.fGetData();
    const oFC = new CFolderCoords;
    oFC.conn = CopyObject(oDTP.oMeta.oConn);
    oFC.conn.sUrlA += oData.BmkKey;
    oFC.sAcctKeyA = oDTP.oMeta.sAccKey;
    oData.pBm.sAcctKeyA = oDTP.oMeta.sAccKey;
    oData.pBm.sServerDirA = oData.BmkKey;
    if (sFieldName == "edit") {
        OpenFolderOptionSets(oData.pBm, oFC.conn.sUrlA, -2, oFC);
    }
    else if (sFieldName == "delete") {
        try {
            await AsyncHtmlConfirm(GetLocaleText("Ask_DeleteBookmark"), "Explorer_OpDelete", eMyConfDefBtn.cancel);
            await SendRecivePostApiWithRetry("DeleteUnnamedBookmark", { bookmark_data: oData.pBm });
            let nSel = oBranch._branch_.dep_ind - 1;
            if (nSel < 0)
                nSel = 0;
            oBranch._branch_.fDeleteSelf();
            oDTP.fSelTabClean();
            oDTP.fSelTabPush(nSel);
            oDTP.ShowTable();
            const nDelBmInd = oDTP.oMeta.aBookmarks.findIndex(it => it.BmkKey == oData.pBm.BmkKey);
            if (nDelBmInd >= 0) {
                oDTP.oMeta.aBookmarks.splice(nDelBmInd, 1);
            }
            if (IsBmEncOrZip(oData.pBm.Opts)) {
                ResetFolderIcon(oDTP.oParentDTP, oFC.conn.sUrlA, oDTP.oMeta.sAccKey, oDTP.oMeta.sHomePath);
            }
        }
        catch (oErr) {
            CatchErrProcess(oErr);
        }
    }
}
function ResetFolderIcon(oDTP, sUrl, sAccKey, sHomePath) {
    if (!oDTP || !sUrl || !sAccKey)
        return;
    const url = ParseUrl(sUrl);
    const aPath = url.pathname.slice(sHomePath.length).split("/");
    aPath.splice(0, 0, sAccKey);
    aPath.splice(0, 0, url.protocol);
    const oBr = oDTP.fFindBranchArr(aPath);
    if (!oBr)
        return;
    const oData = oBr.fGetData();
    oData.icon = "folder";
    delete oData.oBookmark;
    delete oData.sFsHandle;
    delete oData.bIgnoreBookmark;
    oDTP.ShowRows();
}
