Skip to content

Commit

Permalink
Fix: More cases on long paths not working in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm authored Aug 23, 2024
1 parent 549b54c commit 7b1bbdf
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 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 [`bab197f`](https://github.com/ollm/OpenComic/commit/bab197fa11f89ae07a707e4f42ea144a5416f25f)
- Long paths not workin in Windows (paths equal or greater than 260 characters) [`884bccd`](https://github.com/ollm/OpenComic/commit/884bccd153a4cb2775fbfb5f0e7c6575188ec073)
- Long paths not working in Windows (paths equal or greater than 260 characters) [`884bccd`](https://github.com/ollm/OpenComic/commit/884bccd153a4cb2775fbfb5f0e7c6575188ec073)
- Extracting 7zip in separate stacks to avoid errors when extracting many files [`061827f`](https://github.com/ollm/OpenComic/commit/061827fc737aa8edfde14e7b092a8b44e571bf08)
- Prevent scroll event while reading is loading [`4c93a72`](https://github.com/ollm/OpenComic/commit/4c93a724220fc820347464a988727ef4649052fe)
- Multiple errors managing cache of files in servers
Expand Down
18 changes: 18 additions & 0 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@ function copy(toCopy)
}
}

function _shortWindowsPath(path, copyToTmp = false)
{
if(process.platform !== 'win32') return path;

path = shortWindowsPath.generateSync(path);

if(path.length >= 260)
{
if(copyToTmp)
path = fileManager.copyToTmp(path);
else if(!/^\\\\\?/.test(path))
path = '\\\\?\\'+path;
}

return path;
}

var throttles = {};
var debounces = {};

Expand Down Expand Up @@ -317,4 +334,5 @@ module.exports = {
sleep: sleep,
setImmediate: setImmediate,
setThrottle: setThrottle,
shortWindowsPath: _shortWindowsPath,
};
24 changes: 24 additions & 0 deletions scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,29 @@ function dirSizeSync(dir)
return size;
}

function copyToTmp(path)
{
const name = p.basename(path);
const tmp = p.join(tempFolder, sha1(p.dirname(path)));

const newPath = p.join(tmp, sha1(name)+p.extname(name));

if(!fs.existsSync(tmp))
fs.mkdirSync(tmp, {recursive: true});

if(!fs.existsSync(newPath))
fs.copyFileSync(path, newPath);

const tmpUsage = storage.get('tmpUsage');

if(!tmpUsage[newPath]) tmpUsage[newPath] = {};
tmpUsage[newPath].lastAccess = app.time();

storage.setThrottle('tmpUsage', tmpUsage);

return newPath;
}

var prevDevicePixelRatio = window.devicePixelRatio;

window.addEventListener('resize', function() {
Expand Down Expand Up @@ -3213,4 +3236,5 @@ module.exports = {
macosSecurityScopedBookmarks: macosSecurityScopedBookmarks,
dirSize: dirSize,
dirSizeSync: dirSizeSync,
copyToTmp: copyToTmp,
}
12 changes: 6 additions & 6 deletions scripts/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ async function resize(fromImage, toImage, config = {})
{
if(sharp === false) sharp = require('sharp');

fromImage = shortWindowsPath.generateSync(fromImage);
fromImage = app.shortWindowsPath(fromImage);

config = {...{
width: 200,
Expand Down Expand Up @@ -86,7 +86,7 @@ async function resizeToCanvas(fromImage, config = {})
{
if(sharp === false) sharp = require('sharp');

fromImage = shortWindowsPath.generateSync(fromImage);
fromImage = app.shortWindowsPath(fromImage);

config = {...{
// background: 'white',
Expand Down Expand Up @@ -127,7 +127,7 @@ async function resizeToBlob(fromImage, config = {})
{
if(sharp === false) sharp = require('sharp');

fromImage = shortWindowsPath.generateSync(fromImage);
fromImage = app.shortWindowsPath(fromImage);

config = {...{
// background: 'white',
Expand Down Expand Up @@ -222,7 +222,7 @@ async function convertToPng(fromImage, toImage, config = {})
{
if(sharp === false) sharp = require('sharp');

fromImage = shortWindowsPath.generateSync(fromImage);
fromImage = app.shortWindowsPath(fromImage);

config = {...{
// background: 'white',
Expand Down Expand Up @@ -250,7 +250,7 @@ async function convertToWebp(fromImage, toImage, config = {})
{
if(sharp === false) sharp = require('sharp');

fromImage = shortWindowsPath.generateSync(fromImage);
fromImage = app.shortWindowsPath(fromImage);

config = {...{
// background: 'white',
Expand Down Expand Up @@ -396,7 +396,7 @@ async function getSizes(images)
{
if(sharpSupportedFormat(image.image))
{
const _sharp = sharp(shortWindowsPath.generateSync(image.image));
const _sharp = sharp(app.shortWindowsPath(image.image));
const metadata = await _sharp.metadata();

size = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/opencomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ hb.registerHelper('encodeSrcURI', function(string) {

hb.registerHelper('shortWindowsPath', function(string) {

return shortWindowsPath.generateSync(string);
return app.shortWindowsPath(string);

});

Expand Down
6 changes: 3 additions & 3 deletions scripts/reading/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async function render(index, _scale = false, magnifyingGlass = false)
{
if(cssMethods[_config.kernel])
{
img.src = encodeSrcURI(shortWindowsPath.generateSync(img.dataset.src));
img.src = encodeSrcURI(app.shortWindowsPath(img.dataset.src, true));
img.classList.remove('blobRendered', 'blobRender');
img.style.imageRendering = cssMethods[_config.kernel];
}
Expand Down Expand Up @@ -477,14 +477,14 @@ async function render(index, _scale = false, magnifyingGlass = false)
}
else
{
img.src = encodeSrcURI(shortWindowsPath.generateSync(img.dataset.src));
img.src = encodeSrcURI(app.shortWindowsPath(img.dataset.src, true));
img.classList.remove('blobRendered', 'blobRender');
img.style.imageRendering = '';
}
}
else
{
img.src = encodeSrcURI(shortWindowsPath.generateSync(img.dataset.src));
img.src = encodeSrcURI(app.shortWindowsPath(img.dataset.src, true));
img.classList.remove('blobRendered', 'blobRender');
img.style.imageRendering = '';
}
Expand Down

0 comments on commit 7b1bbdf

Please sign in to comment.