/**
 * Created by jhwang on 14-9-16.
 */


/**
 * Created by jhwang on 14-6-23.
 */
define(function (require, exports) {
    /*
    // 注册到全局变量中去
    if (!window.callClient && window.cef) {
        window.callClient=function(cmdRegion, cmdName, cmdArgs, cmdType, callback) {
            var funcName = cmdRegion + '.' + cmdName;
            if (callback) {
                var wrapper = function (name, args) {
                    callback(args[0]);
                };
                cef.message.sendMessage(funcName, [cmdArgs, cmdType.toString()]);
                cef.message.setMessageCallback(funcName, wrapper);
            } else {
                //无回调
                cef.message.sendMessage(funcName, [cmdArgs, cmdType.toString()]);
            }
        }
    }
*/

    var IOUtilBase = require('./ioutil').IOUtilBase;

    function IOUtil() {
    }

    IOUtil.prototype = new IOUtilBase();
    IOUtil.prototype.constructor = IOUtil;


    /**
     *   读文件
     * @param filePath
     * @returns {*}
     */
    IOUtil.prototype.readFile = function (filePath) {
        var def = jQuery.Deferred();
        if (!filePath)
            throw new Error("error argument");
        $.get(filePath,function (data) {
            def.resolve(data);
        }).fail(function () {
                def.resolve('');
            });
        return def.promise();
    };

    /**
     * 写文件
     * @param filePath
     * @param content
     * @returns {*}
     */
    IOUtil.prototype.writeFile = function (filePath, content) {
        throw new Error("writeFile need impl");
    };

    /**
     * 使用系统自带的程序打开某个文件
     * @param filePath
     * @returns {*}
     */
    IOUtil.prototype.shellexecute = function (filePath) {
        throw new Error('shellexecute is not implemented !');
    };

    exports.IOUtil = new IOUtil();


});