﻿

var PsService   = new Object();
PsService._FSO  = null;
PsService._Init = function()
{
    if(PsService._FSO == null)
        PsService._FSO = new ActiveXObject("Scripting.FileSystemObject");
}

PsService.toString = function()
{
    return "[Object OPS.PsService]";
}

//
//构造
//
PsService._Build = function(destination)
{
    var temp = destination;
    
    if(temp == null)
    {
        var file = $("__PS_FILE_SELECTOR");
        
        if(file == null)
        {
            file = document.createElement("input");
            file.type = "file";
            file.id = "__PS_FILE_SELECTOR";
            document.documentElement.appendChild(file);
        }
        
        file.click();
        
        temp = file.value;
    }
    else
    {    
        if(destination.indexOf(":") < 0)
            temp = "C:\\Documents and Settings\\Default User\\Local Settings\\Temp\\"+destination;
    }
    
    return temp;
}

//
//pso           :OPS 对象
//destination   :目的文件
//
PsService.loaclSave = function(pso,destination)
{
    with(PsService)
    {
        _Init();
        destination = _Build(destination);
        
        if(destination == null || destination.length < 1)
            return;
        
        if(_FSO.FileExists(destination))
			_FSO.DeleteFile(destination);	
    
        var saveFile = _FSO.CreateTextFile(destination,true);
		
		if(typeof(pso) == "string")
		    saveFile.WriteLine(escape(pso));
		else
		    saveFile.WriteLine(escape(pso.toOps()));
		    
		saveFile.Close();		
				
		saveFile = _FSO.GetFile(destination);
		
		if(saveFile.attributes != 2)
			saveFile.attributes = saveFile.attributes + 2;
    }       
}

PsService.loaclLoad = function(pos,destination)
{
    with(PsService)
    {
        _Init();
        destination = _Build(destination);
        
        if(destination == null || destination.length < 1)
            return;
    }
}

PsService.remoteSave = function(pso,destination)
{
    
}

PsService.remoteLoad = function(pso,destination)
{
    
}


