Skip to content

Commit

Permalink
修复中文路径问题
Browse files Browse the repository at this point in the history
  • Loading branch information
188080501 committed Apr 1, 2017
1 parent 5a956d9 commit 203dd61
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
8 changes: 8 additions & 0 deletions components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ void Manage::startOptimize(const QString &currentFilePath)
waitOptimizeQueue_.remove( currentFilePath );
}

QString Manage::urlToLocalPngOrJpgFilePath(const QVariant &url)
{
QFileInfo fileInfo( url.toUrl().toLocalFile() );
if ( !fileInfo.isFile() ) { return { }; }
if ( !fileInfo.filePath().toLower().endsWith( ".png" ) && !fileInfo.filePath().toLower().endsWith( ".jpg" ) ) { return { }; }
return fileInfo.filePath();
}

QString Manage::optimizeJpg(const bool &coverOldFile, const QStringList &filePaths)
{
QString targetDir;
Expand Down
2 changes: 2 additions & 0 deletions components/ToolsGroup/JpgOptimize/cpp/jpgoptimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public slots:

void startOptimize(const QString &currentFilePath);

QString urlToLocalPngOrJpgFilePath(const QVariant &url);

private:
QString optimizeJpg(const bool &coverOldFile, const QStringList &filePaths);

Expand Down
7 changes: 3 additions & 4 deletions components/ToolsGroup/JpgOptimize/qml/JpgOptimize.qml
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,11 @@ Item {

for( var index = 0; index < drop.urls.length; ++index )
{
var url = drop.urls[ index ].toString();
var pngOrJpgFilePath = jpgOptimizeManage.urlToLocalPngOrJpgFilePath( drop.urls[ index ] );

if ( url.indexOf( "file://" ) !== 0 ) { return; }
if ( url.toLowerCase().lastIndexOf( ".jpg" ) !== ( url.length - 4 ) ) { return; }
if ( pngOrJpgFilePath.length === 0 ) { continue; }

filePaths.push( url.substr( 7 ) );
filePaths.push( pngOrJpgFilePath);
}

if ( filePaths.length === 0 ) { return; }
Expand Down
8 changes: 8 additions & 0 deletions components/ToolsGroup/PngOptimize/cpp/pngoptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ void Manage::startOptimize(const QString &currentFilePath)
waitOptimizeQueue_.remove( currentFilePath );
}

QString Manage::urlToLocalPngFilePath(const QVariant &url)
{
QFileInfo fileInfo( url.toUrl().toLocalFile() );
if ( !fileInfo.isFile() ) { return { }; }
if ( !fileInfo.filePath().toLower().endsWith( ".png" ) ) { return { }; }
return fileInfo.filePath();
}

QString Manage::optimizePng(const bool &coverOldFile, const QStringList &filePaths)
{
QString targetDir;
Expand Down
2 changes: 2 additions & 0 deletions components/ToolsGroup/PngOptimize/cpp/pngoptimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public slots:

void startOptimize(const QString &currentFilePath);

QString urlToLocalPngFilePath(const QVariant &url);

private:
QString optimizePng(const bool &coverOldFile, const QStringList &filePaths);

Expand Down
7 changes: 3 additions & 4 deletions components/ToolsGroup/PngOptimize/qml/PngOptimize.qml
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,11 @@ Item {

for( var index = 0; index < drop.urls.length; ++index )
{
var url = drop.urls[ index ].toString();
var pngFilePath = pngOptimizeManage.urlToLocalPngFilePath( drop.urls[ index ] );

if ( url.indexOf( "file://" ) !== 0 ) { return; }
if ( url.toLowerCase().lastIndexOf( ".png" ) !== ( url.length - 4 ) ) { return; }
if ( pngFilePath.length === 0 ) { continue; }

filePaths.push( url.substr( 7 ) );
filePaths.push( pngFilePath);
}

if ( filePaths.length === 0 ) { return; }
Expand Down
6 changes: 3 additions & 3 deletions lib/JQLibrary/src/JQZopfli/JQZopfli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,17 @@ OptimizeResult JQZopfli::optimize(const QString &originalFilePath, const QString
std::vector< unsigned char > originalPng;
std::vector< unsigned char > resultPng;

if ( lodepng::load_file( originalPng, originalFilePath.toUtf8().data() ) )
if ( lodepng::load_file( originalPng, originalFilePath.toLocal8Bit().data() ) )
{
qDebug() << "JQZopfli::optimize: error2";
return result;
}

result.originalSize = originalPng.size();

ZopfliPNGOptions png_options;
ZopfliPNGOptions pngOptions;

if ( ZopfliPNGOptimize( originalPng, png_options, png_options.verbose, &resultPng ) )
if ( ZopfliPNGOptimize( originalPng, pngOptions, pngOptions.verbose, &resultPng ) )
{
qDebug() << "JQZopfli::optimize: error3";
return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/JQToolsLibrary/include/JQToolsLibrary.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <QObject>
#include <QPointer>

#define JQTOOLS_VERSIONSTRING "17.3.26"
#define JQTOOLS_VERSIONSTRING "17.4.1"

class QQmlApplicationEngine;

Expand Down

0 comments on commit 203dd61

Please sign in to comment.