/////////////////////////////////////////////////////////////////////
//
// DeveloperStartPage.js - implementation of script used 
//                         only for Developer Start Page
//
// Copyright ? 2001-2003 InstallShield Software Corporation
//

// project type constants
var PROJECTTYPE_BASICMSI_START    = 0;
var PROJECTTYPE_MERGEMODULE_START = 1;
var PROJECTTYPE_STANDARD_START    = 2;
var PROJECTTYPE_QUICKPATCH_START  = 3;
var PROJECTTYPE_TRANSFORM_START   = 4;
var PROJECTTYPE_MSIDIRECT_START   = 5;
var PROJECTTYPE_MSMDIRECT_START   = 6;
var PROJECTTYPE_WEB_START         = 7;
var PROJECTTYPE_ISOBJECT_START    = 8;
var PROJECTTYPE_PRO_START         = 9;
var PROJECTTYPE_PROOBJECT_START   = 10;
var PROJECTTYPE_CE_START          = 11;
var PROJECTTYPE_MSP_START         = 12;
var PROJECTTYPE_CLICKONCE_START   = 13;
var PROJECTTYPE_LITE_START        = 17;

function GetProjectTypeString(pType) {
	switch (pType) {
    case PROJECTTYPE_BASICMSI_START:
       return "基本 MSI";
    case PROJECTTYPE_MERGEMODULE_START:
       return "合并模块";   
    case PROJECTTYPE_STANDARD_START:
       return "InstallScript MSI";   
	case PROJECTTYPE_QUICKPATCH_START:
       return "QuickPatch";
    case PROJECTTYPE_MSIDIRECT_START:
       return "MSI 文件";
    case PROJECTTYPE_MSMDIRECT_START:
       return "MSM 文件";
    case PROJECTTYPE_WEB_START:
	   return "Web 工程";
	case PROJECTTYPE_ISOBJECT_START:
	   return "InstallScript MSI 对象";
    case PROJECTTYPE_TRANSFORM_START:
	   return "转换"; 
	case PROJECTTYPE_PRO_START:
	   return "InstallScript";   
 	case PROJECTTYPE_PROOBJECT_START:
	   return "InstallScript 对象"; 
	case PROJECTTYPE_CE_START:
	   return "智能设备"; 
 	case PROJECTTYPE_MSP_START:
	   return "MSP"; 
	case PROJECTTYPE_CLICKONCE_START:
	   return "ClickOnce"; 
	case PROJECTTYPE_LITE_START:
	   return "压缩工程"; 
	default:
	    return "";
   }    
   return "";
}

function InitializeDeveloperStartPage() {
    window.onerror = HandleError;
    window.setTimeout("InitializeTabControl();", 1);
    
	if (IsMemberCEIP())
	{
	    document.all("CEIP1").style.visibility = "hidden";
	    document.all("CEIP2").style.visibility = "hidden";
	}
    
    var main = AfxGetMain();
    var mruList = main.RecentFiles;
    var insertAt = 0;
    var maxFiles = 8;

    for (var i = 0; i < mruList.Count; i++) {
        var file = mruList.Item(i);
        var filePath = new String(file.sFullFileName);
        var fileType = file.lFileType;
        var fileTypeString = GetProjectTypeString(fileType);
        
        if (DoesFileExist(filePath)) {
            var formattedFile = filePath.substr(filePath.lastIndexOf("\\") + 1, filePath.length);
            
            var dateModified = GetFileDateLastModified(filePath);
            var formattedDate = new String(dateModified.toLocaleString());
            
            var filePathEsc = filePath.replace(/\\/g, "\\\\"); // need to escape backslashes, before writing in page script
            
            var template = new String(divMRUTemplate.innerHTML);
            template = template.replace(/TOOLTIP/, filePath);
            template = template.replace(/FILEPATH/, filePathEsc);
            template = template.replace(/FILENAME/, formattedFile);
            
            document.all("tdProjectName" + insertAt).innerHTML = template;
            document.all("tdProjectType" + insertAt).innerHTML = fileTypeString;
            document.all("tdProjectModified" + insertAt).innerHTML = formattedDate;
            
            insertAt++;
            
            if (insertAt > (maxFiles - 1)) {
                break;
            }
        }
    }
        
    return;
}

function RefreshData() {
	InitializeDeveloperStartPage();
}

function HandleError(message, url, line) {
    var file = new ActiveXObject("ISProxy.Proxy");
    file.ISCreateObject(document, "isutil.dll", "{A5CF09AF-F2FC-4E5D-9F7D-419D28130E62}");
    file.LogError(message, url, line);
    
    window.event.returnValue = true;
    
    return true;
}

function InitializeTabControl() {
    // each page should have an OBJECT tag {B0A36422-2379-11d4-AB3B-00C04F09719C}, 
    // named 'tabControl', that enables tab access to any HTML document in the IDE
    var tabControl = document.all("tabControl");
    
    if (IsRealObject(tabControl)) {
        tabControl.Initialize(document);
    }
    
    return;
}

function AfxGetApp() {
    var objMgr = new ActiveXObject("ISProxy.Proxy");
    objMgr.ISCreateObject(document, "isobjmgr.dll", "{DE5FBA5D-8AB0-4a53-B620-F2065702D228}");
    return objMgr.pApp;
}

function AfxGetMain() {
    var app = AfxGetApp();
    return app.GetMain();
}

function AfxGetNav() {
    var app = AfxGetApp();
    return app.GetNav();
}

function AfxGetStore() {
    var main = AfxGetMain();
    return main.m_pStore;
}

function AfxGetDB() {
    var store = AfxGetStore();
    return store.hDb;
}

function AfxGetProject() {
    var store = AfxGetStore();
    return store.hProject;
}

function GotoView(view) {
    var nav = AfxGetNav();
    nav.GoToNode(view);
    
    var app = AfxGetApp();
    app.FocusToIDE();
    
    return false;
}

function GenerateCommand(command) {
    var app = AfxGetApp();
    var cmdRouter = app.GetCmdRouter();
    
    var data, handled;
    cmdRouter.GenerateCmd(command, data, handled);
    
    return false;
}

function OpenProject(path) {
    var main = AfxGetMain();
    main.DoOpenProject(path, 2, true, true, false, "");
    
    return false;
}

function OpenHelpTopic(topic) {
    var app = AfxGetApp();
    app.ShowHelp(topic);
    
    return false;
}

function OpenProjectWizard() {
    var main = AfxGetMain();
    main.OpenProjectWizard();
    
    return false;
}

function OpenTutorial() {
    var main = AfxGetMain();
    main.OpenTutorial();
    
    return false;
}

function OpenSamplesFolder() {
    var main = AfxGetMain();
    var productPath = main.DirMainProduct;
    var samplesPath = productPath + "\\Samples"; // Is this folder name localized?
    
    var app = AfxGetApp();
    app.OpenWindow(samplesPath, "", "", false);
    
    return false;
}

function IsMemberCEIP() {
    var appSettings = new ActiveXObject("ISProxy.Proxy");
    appSettings.ISCreateObject(document, "isappservices.dll", "{FD4CCFF8-13A5-44AE-AE27-33D7F91B03FF}");
    
    return appSettings.MemberCEIP;
}

function DoesFileExist(filePath) {
    var app = AfxGetApp();
    var fso = app.pFso;
    var exists = fso.FileExists(filePath);
    
    return exists;
}

function GetFileDateLastModified(filePath) {
    var app = AfxGetApp();
    var fso = app.pFso;
    var file = fso.GetFile(filePath);
    var modified = new Date(file.DateLastModified);
    
    return modified;
}

function IsRealObject(obj) {
    var ok = false;
    
    if (obj && (typeof(obj) == "object")) {
        ok = true;
    }
    
    return ok;
}
