Skip to content

Commit

Permalink
Fix: Server connection in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm authored Jan 12, 2024
1 parent 16aef6c commit 7c08f24
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ function setServerInOfflineMode(value = false)

function isServer(path)
{
if(/^(?:smb|ssh|sftp|scp|ftp|ftps)\:\/\/?/.test(path))
if(/^(?:smb|ssh|sftp|scp|ftp|ftps)\:[\/\\]{1,2}/.test(path))
return true;

return false;
Expand Down
39 changes: 30 additions & 9 deletions scripts/server-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,81 @@ var servers = [];

function getHost(path)
{
path = posixPath(path);

return app.extract(/^[a-z]+\:\/\/?([^\/\\:]+)(:[0-9]+)?/, path, 1);
}

function getShare(path)
{
path = posixPath(path);

return app.extract(/^[a-z]+\:\/\/?[^\/\\]+\/([^\/\\]+)/, path, 1);
}

function getPath(path)
{
path = posixPath(path);

return app.extract(/^[a-z]+\:\/\/?[^\/\\]+\/(.+)/, path, 1);
}

function getPathWithoutShare(path)
{
path = posixPath(path);

return app.extract(/^[a-z]+\:\/\/?[^\/\\]+\/[^\/\\]+\/(.+)/, path, 1);
}

function getPort(path)
{
path = posixPath(path);

return +app.extract(/^[a-z]+\:\/\/?[^\/\\]+:([0-9]+)\//, path, 1);
}

function getAdress(path)
{
path = posixPath(path);

if(/^(?:smb)\:\//.test(path))
return fixPath(app.extract(/^((?:smb)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:smb)\:\/\/[^\/\\]+)/, path, 1);
else if(/^(?:ftps?)\:\//.test(path))
return fixPath(app.extract(/^((?:ftps?)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:ftps?)\:\/\/[^\/\\]+)/, path, 1);
else if(/^(?:sftp|ssh)\:\//.test(path))
return fixPath(app.extract(/^((?:sftp|ssh)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:sftp|ssh)\:\/\/[^\/\\]+)/, path, 1);
else if(/^(?:scp)\:\//.test(path))
return fixPath(app.extract(/^((?:scp)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:scp)\:\/\/[^\/\\]+)/, path, 1);

return '';
}

function getTypeAdress(path)
{
path = posixPath(path);

if(/^(?:smb)\:\//.test(path))
return fixPath(app.extract(/^((?:smb)\:\/\/?[^\/\\]+\/[^\/\\]+)/, path, 1));
return app.extract(/^((?:smb)\:\/\/[^\/\\]+\/[^\/\\]+)/, path, 1);
else if(/^(?:ftps?)\:\//.test(path))
return fixPath(app.extract(/^((?:ftps?)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:ftps?)\:\/\/[^\/\\]+)/, path, 1);
else if(/^(?:sftp|ssh)\:\//.test(path))
return fixPath(app.extract(/^((?:sftp|ssh)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:sftp|ssh)\:\/\/[^\/\\]+)/, path, 1);
else if(/^(?:scp)\:\//.test(path))
return fixPath(app.extract(/^((?:scp)\:\/\/?[^\/\\]+)/, path, 1));
return app.extract(/^((?:scp)\:\/\/[^\/\\]+)/, path, 1);

return '';
}

function posixPath(path)
{
path = path.split(p.sep).join(p.posix.sep);
return path.replace(/^([a-z]+)\:[\/\\]{1,2}/, '$1://');
}

function fixPath(path)
{
return path.replace(/^([a-z]+)\:\/\/?/, '$1://');
path = p.normalize(path);
return path.replace(/^([a-z]+)\:[\/\\]{1,2}/, '$1:'+p.sep+p.sep);
}

var serverLastError = false;
Expand Down

0 comments on commit 7c08f24

Please sign in to comment.