/**
 * utils
 */

var require = global.require;
var gui = global.gui;

var Utils = {
    // 在本地文件窗口中展示文件
    showFileInFolder: function(filePath) {
        gui.Shell.showItemInFolder(filePath);
    },

    // 调用系统打开方式来打开文件
    openFileExternal: function(filePath) {
        gui.Shell.openItem(filePath);
    },

    // get file format
    getFileFormat: function(str) {
        var format = str.substr(str.lastIndexOf('.') + 1);

        return format;
    }
};

module.exports = Utils;
@@ -49,24 +49,108 @@
 var 
-gui = global.gui
+fs = require('fs');%0Avar iconv = require('iconv-lite');%0A%0Avar gui = global.gui;%0Avar mass = global.mass
 ;%0A%0Av
@@ -335,32 +335,32 @@
 ion(filePath) %7B%0A
-
         gui.Shel
@@ -385,24 +385,1803 @@
 h);%0A    %7D,%0A%0A
+    // %E8%BD%BD%E5%85%A5%E6%96%87%E4%BB%B6%0A    loadFile: function(filePath, callback) %7B%0A        var self = this;%0A        var encodings = %5B'utf-8', 'gbk', 'gb2312', 'ascii', 'binary', 'base64'%5D;%0A%0A        // %E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%E6%AD%A4%E6%96%87%E4%BB%B6%0A        if (fs.existsSync(filePath)) %7B%0A%0A            fs.readFile(filePath, function(err, data) %7B%0A                if (err) return console.log(err);%0A%0A                var decodeData = self.str_decode(data);%0A%0A                if (decodeData === 'error') %7B%0A                    mass.dialog('%E6%96%87%E4%BB%B6%E8%A7%A3%E6%9E%90%E5%87%BA%E9%94%99%EF%BC%81%E8%AF%B7%E6%A3%80%E6%9F%A5%E6%96%87%E4%BB%B6%E7%BC%96%E7%A0%81%E7%B1%BB%E5%9E%8B', true);%0A                    return;%0A                %7D%0A%0A                var encode = 'utf-8';%0A%0A                // %E7%BC%96%E7%A0%81%E4%B8%8D%E5%AF%B9%E8%AF%95%E7%9D%80%E7%94%A8%E5%88%AB%E7%9A%84%E7%BC%96%E7%A0%81%0A                if (decodeData.indexOf('%EF%BF%BD') != -1) %7B%0A                    for (var i = 0, len = encodings.length; i %3C len; i++) %7B%0A                        decodeData = iconv.decode(data, encodings%5Bi%5D);%0A                        if (decodeData.indexOf('%EF%BF%BD') == -1) %7B%0A                            encode = encodings%5Bi%5D;%0A                            console.log('%E6%96%87%E4%BB%B6%E7%BC%96%E7%A0%81%EF%BC%9A ' + encodings%5Bi%5D);%0A                            break;%0A                        %7D%0A                    %7D%0A                %7D%0A%0A                callback(decodeData, encode);%0A            %7D);%0A        %7D%0A    %7D,%0A%0A    // %E5%AD%97%E7%AC%A6%E8%A7%A3%E7%A0%81%0A    str_decode: function(buf, encode) %7B%0A        if (!buf) return '';%0A%0A        encode = encode %7C%7C 'utf-8';%0A%0A        var encodings = %5B'utf-8', 'gbk', 'gb2312', 'ascii', 'binary', 'base64'%5D;%0A        var result = 'error';%0A        var tryTimes = 0;%0A%0A        (function() %7B%0A            var args = arguments;%0A%0A            try%7B%0A                result = iconv.decode(buf, encode);%0A            %7D%0A            catch(e) %7B%0A                if (encodings%5BtryTimes%5D) %7B%0A                    tryTimes++;%0A                    args.callee();%0A                %7D%0A            %7D%0A        %7D)();%0A%0A        return result;%0A    %7D,%0A%0A
     // get f

update utils