Skip to content

Commit

Permalink
Fix: Files shared over a network in Windows do not open
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm authored May 29, 2024
1 parent 2853f35 commit bab197f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Optimized index loading and folder navigation [`0e6000f`](https://github.com/ollm/OpenComic/commit/0e6000f00e445de98eab7cdfbf72ee9b0016bf26)
- Error extracting files with 7zip if the file name contained UTF8 characters [`27c863b`](https://github.com/ollm/OpenComic/commit/27c863b6a9abd434e8855216100e5f8087ed1e73)
- Fullscreen error [`d72813a`](https://github.com/ollm/OpenComic/commit/d72813abbb0320a94bee5b2881c2bfcd1f2084cf)
- Files shared over a network in Windows do not open

## [v1.2.0](https://github.com/ollm/OpenComic/releases/tag/v1.2.0) (29-03-2024)

Expand Down
29 changes: 20 additions & 9 deletions scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ var file = function(path, _config = false) {

this.readFromFilesList = function(files, path, lastCompressed) {

let segments = removePathPart(path, lastCompressed).split(p.sep);
let segments = splitPath(removePathPart(path, lastCompressed));

return this._readFromFilesList(segments, files);

Expand Down Expand Up @@ -802,7 +802,7 @@ var file = function(path, _config = false) {
if(macosMAS)
{
let securityScopedBookmarks = storage.get('securityScopedBookmarks');
let segments = path.split(p.sep);
let segments = splitPath(path);

if(!segments[0])
segments[0] = p.sep;
Expand Down Expand Up @@ -1582,7 +1582,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
{
let file = files[i];
let fileIndex = i;
let segments = file.name.split(p.sep);
let segments = splitPath(file.name);

let dimension = dimensions;

Expand Down Expand Up @@ -2559,7 +2559,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
if(macosMAS)
{
let securityScopedBookmarks = storage.get('securityScopedBookmarks');
let segments = path.split(p.sep);
let segments = splitPath(path);

if(!segments[0])
segments[0] = p.sep;
Expand Down Expand Up @@ -2704,7 +2704,7 @@ function downloadedCompressedFile(path)

function realPath(path, index = 0, prefixes = false)
{
let segments = path.split(p.sep);
let segments = splitPath(path);
let len = segments.length;

let virtualPath;
Expand Down Expand Up @@ -2786,7 +2786,7 @@ function isCompressed(name)

function firstCompressedFile(path, index = 0, checkDirectory = true)
{
let segments = path.split(p.sep);
let segments = splitPath(path);
let len = segments.length;

let newPath = (len > 0) ? (isEmpty(segments[0]) ? '/' : segments[0]) : '';
Expand Down Expand Up @@ -2818,7 +2818,7 @@ function firstCompressedFileRealPath(path, index = 0)

function lastCompressedFile(path, index = 0)
{
let segments = path.split(p.sep);
let segments = splitPath(path);
let len = segments.length;

let newPath = (len > 0) ? (isEmpty(segments[0]) ? '/' : segments[0]) : '';
Expand All @@ -2844,7 +2844,7 @@ function lastCompressedFile(path, index = 0)

function allCompressedFiles(path, index = 0)
{
let segments = path.split(p.sep);
let segments = splitPath(path);
let len = segments.length;

let newPath = (len > 0) ? (isEmpty(segments[0]) ? '/' : segments[0]) : '';
Expand Down Expand Up @@ -2872,7 +2872,7 @@ function allCompressedFiles(path, index = 0)

function containsCompressed(path, index = 0)
{
let segments = path.split(p.sep);
let segments = splitPath(path);
let len = segments.length;

var virtualPath = (len > 0) ? (isEmpty(segments[0]) ? '/' : segments[0]) : '';
Expand All @@ -2898,6 +2898,16 @@ function containsCompressed(path, index = 0)
return false;
}

function splitPath(path)
{
const first = app.extract(/^([\\\/]*[^\\\/]+)[\\\/]*/, path);
const segments = path.replace(/^([\\\/]*[^\\\/]+)[\\\/]*/, '').split(p.sep).filter(i => i);

segments.unshift(first);

return segments;
}

function isParentPath(parentPath, fullPath)
{
if(new RegExp('^\s*'+pregQuote(parentPath)).test(fullPath))
Expand Down Expand Up @@ -3089,6 +3099,7 @@ module.exports = {
firstCompressedFile: firstCompressedFile,
lastCompressedFile: lastCompressedFile,
containsCompressed: containsCompressed,
splitPath: splitPath,
isParentPath: isParentPath,
simpleExists: simpleExists,
replaceReservedCharacters: replaceReservedCharacters,
Expand Down
4 changes: 2 additions & 2 deletions scripts/opencomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ function showAboutWindow()

function escapeBackSlash(string)
{
return string.replace(/\\+/g, '\\\\');
return string.replace(/\\/g, '\\\\');
}

function invertBackslash(string)
Expand All @@ -918,7 +918,7 @@ function invertBackslash(string)

function encodeSrcURI(string)
{
let segments = string.split(p.sep);
let segments = fileManager.splitPath(string);

for(let i in segments)
{
Expand Down

0 comments on commit bab197f

Please sign in to comment.