//快捷方式
import com.interface.IShellLink;
import fsys; 
namespace fsys.lnk;

//调用com静态接口
shlnk = ..com.interface.create("{00021401-0000-0000-C000-000000000046}",..com.interface.IShellLink );
file = shlnk.QueryInterface(..com.interface.IPersistFile);

getPath = function(lnkpath){
	hr = file.Load( ..string.toUnicode( lnkpath ) ,0);
	if( hr>=0 /*SUCCEEDED*/ ){ 
		//读取快捷方式指向的目标路径
		hr,path = shlnk.GetPath(1024, 1024, {}, 0x2/*_SLGP_UNCPRIORITY*/); 
	
		//读取快捷方式运行参数
		hr,arg = shlnk.GetArguments(1024, 1024);
		return  path,arg;
	}
	else {
		error( ..lasterr(),2 )
	} 
}

searchLnk =function(pattern,dir){
    pattern = ..string.lower(pattern) 
    var retpath,targetpath;
    ..fsys.enum( dir, 
                "*.lnk", 
                function(dir,filename){ 
                    if(filename){  
                    	targetpath  =  getPath( ..fsys.joinpath(dir,filename) )
                        if(..string.find( ..string.lower(targetpath),pattern)){
                        	retpath = targetpath
                        	return false;
                        }
                    }    
                } 
              );
   return retpath;
}
 
search = function(filename){
	var dir = ..io.localpath("\");
	
	return ..fsys.searchFile(filename) 
		|| searchLnk( filename, ..fsys.getSpecial(0x0000 /*_CSIDL_DESKTOP*/ ) )
		|| searchLnk( filename, ..fsys.getSpecial(0x0002 /*_CSIDL_PROGRAMS*/  )) 
}


/**intellisense(fsys.lnk)
getPath(__/*lnk文件路径*/) = 解析lnk文件,返回快捷方式指向的目标路径
search("__/*文件名*/") = 按下列顺序搜索文件: 桌面快捷方式、应用程序快捷方式
end intellisense**/


