Example #1
0
        public AppInfo CreateNewAppInfo(AppType appType, string appName, string execPath, string imagePath)
        {
            if (execPath == null)
            {
                execPath = String.Empty;
            }

            AppInfo newInfo = new AppInfo()
            {
                AppName = appName,
                ID      = _LastAppInfoID++
            };

            if (LnkHelper.CompareIconPath(execPath, imagePath))
            {
                imagePath = String.Empty;
            }

            newInfo.ImagePath  = imagePath;
            newInfo.ExecPath   = execPath;
            newInfo.NeedImage += (s, e) => OnNeedAppImage(s as AppInfo);
            newInfo.RequestAppImage();
            newInfo.SetAutoAppName();

            if (appType != null)
            {
                appType.AppInfos.Add(newInfo);
            }

            return(newInfo);
        }
Example #2
0
 private static void CreateLnk(object state)
 {
     try
     {
         AppInfo ai       = state as AppInfo;
         string  tempLink = Path.Combine(Path.GetTempPath(), ai.AppName + ".lnk");
         LnkHelper.CreateLnk(tempLink, ai.AppPath, ai.LoadImagePath, ai.AppArgs);
     }
     catch
     {; }
 }
Example #3
0
        private bool SetLnk(ref bool isLnkDirectory,
                            ref string resolvedLnkPath)
        {
            bool handled = false;

            resolvedLnkPath = LnkHelper.GetResolvedFileName(TargetFilePath);
            if (LnkHelper.IsDirectory(resolvedLnkPath))
            {
                Icon = IconReader.GetFolderIcon(TargetFilePath,
                                                IconReader.FolderType.Open, true);
                handled        = true;
                isLnkDirectory = true;
            }
            else if (string.IsNullOrEmpty(resolvedLnkPath))
            {
                Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon");
#warning [Feature] Resolve network root #48, start here
            }
            else
            {
                IWshShell    shell = new WshShell();
                IWshShortcut lnk   = shell.CreateShortcut(TargetFilePath)
                                     as IWshShortcut;
                Arguments        = lnk.Arguments;
                WorkingDirectory = lnk.WorkingDirectory;
                string iconLocation = lnk.IconLocation;
                if (iconLocation.Length > 2)
                {
                    iconLocation = iconLocation.Substring(0,
                                                          iconLocation.Length - 2);
                    if (System.IO.File.Exists(iconLocation))
                    {
                        try
                        {
                            Icon    = Icon.ExtractAssociatedIcon(iconLocation);
                            handled = true;
                        }
                        catch (ArgumentException ex)
                        {
                            Log.Warn($"iconLocation:'{iconLocation}'", ex);
                        }
                    }
                }

                TargetFilePath = resolvedLnkPath;
            }

            SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig));

            return(handled);
        }
Example #4
0
        private void HandleDropFile(IDropInfo dropInfo)
        {
            var oleData = dropInfo.Data as System.Windows.IDataObject;

            if (oleData == null)
            {
                return;
            }

            string[] files = (string[])oleData.GetData(DataFormats.FileDrop);
            foreach (var file in files)
            {
                if (file.EndsWith(".lnk"))
                {
                    string title, command, args, description, iconLocation;
                    int    index;
                    LnkHelper.ResolveShortcut(file, out title, out command, out args, out description, out iconLocation, out index);

                    // todo: 把参数加上
                    Shortcut info = new Shortcut()
                    {
                        Title       = title,
                        Description = description,
                        Icon        = iconLocation,
                        Command     = command
                    };

                    Add(info);
                }
                else if (file.EndsWith(".exe"))
                {
                    System.Diagnostics.FileVersionInfo versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(file);
                    Shortcut info = new Shortcut()
                    {
                        Title       = versionInfo.ProductName,
                        Description = versionInfo.FileDescription,
                        Icon        = null,
                        Command     = file
                    };

                    Add(info);
                }
                else
                {
                    continue;
                }
            }
        }
Example #5
0
    public bool Run(string FilePath, bool RunStaticAnalysis)
    {
        if (m_InTask)
        {
            return(false);
        }
        string ProgramName = FilePath;

        if (ProgramName.ToLower().EndsWith(".lnk"))
        {
            ProgramName = LnkHelper.GetShortcutTargetFile(ProgramName);
            if (string.IsNullOrEmpty(ProgramName))
            {
                m_NotifyError("Couldn't resolve symbolic link");
                CleanupVars();
                return(false);
            }
        }

        if (!ProgramName.ToLower().EndsWith(".exe"))
        {
            m_NotifyError("Only *.exe (PE files) are supported");
            CleanupVars();
            return(false);
        }


        m_FilePath = FilePath;

        if (CheckStaticAnalysisResultIsPersent(FilePath))
        {
            m_NotifyStatus("Found the last static analysis result");
            CleanupVars();
            RunStaticAnalysis = false;
        }

        if (!RunStaticAnalysis)
        {
            CreateProcessAndExit(ProgramName);
        }


        m_InTask = true;
        return(RunStaticAnalysisSubProcess(ProgramName));
    }
Example #6
0
    public bool Run(string FilePath)
    {
        string ProgramName = FilePath;

        if (ProgramName.ToLower().EndsWith(".lnk"))
        {
            ProgramName = LnkHelper.GetShortcutTargetFile(ProgramName);
            if (string.IsNullOrEmpty(ProgramName))
            {
                NotifyError("Couldn't resolve symbolic link");
                return(false);
            }
        }

        if (!ProgramName.ToLower().EndsWith(".exe"))
        {
            NotifyError("Only *.exe (PE files) are supported");
            return(false);
        }

        CreateProcessWithDll(FilePath);
        Environment.Exit(0);
        return(true);
    }
Example #7
0
        protected AppInfo GetAppInfo(string path, bool onlyPrograms, Dictionary <string, object> uniq)
        {
            //Add files
            if (File.Exists(path))
            {
                string ext       = System.IO.Path.GetExtension(path).ToLower();
                string fullPath  = String.Empty;
                string appPath   = String.Empty;
                string appArgs   = String.Empty;
                string imagePath = String.Empty;

                if (ext == ".lnk")
                {
                    var shortcut = LnkHelper.OpenLnk(path);

                    appPath = shortcut.TargetPath;
                    appArgs = shortcut.Arguments;
                    var icoLocation = shortcut.IconLocation;

                    if (appArgs == null)
                    {
                        appArgs = String.Empty;
                    }

                    if (appPath.Contains("{"))
                    {
                        appPath = MsiShortcutParser.ParseShortcut(path);
                    }
                    else if (!icoLocation.Contains("{"))
                    {
                        imagePath = icoLocation;
                    }

                    if (!String.IsNullOrEmpty(appArgs))
                    {
                        fullPath = "\"" + appPath + "\"" + " " + appArgs;
                    }
                    else
                    {
                        fullPath = appPath;
                    }

                    if (!String.IsNullOrEmpty(imagePath))
                    {
                        var imageLocation = imagePath.Split(',');
                        if (imageLocation.Length > 0)
                        {
                            imagePath = imageLocation[0].Trim();
                        }
                        else
                        {
                            imagePath = String.Empty;
                        }
                    }
                }
                else
                {
                    appPath = fullPath = path;
                }

                if (String.IsNullOrEmpty(appPath))
                {
                    return(null);
                }
                //continue;

                if (onlyPrograms && !FilterApps(appPath, appArgs))
                {
                    return(null);
                }
                //continue;

                if (!String.IsNullOrEmpty(fullPath))
                {
                    if (!uniq.ContainsKey(fullPath.ToLower()))
                    {
                        string appName = Path.GetFileNameWithoutExtension(path);
                        uniq.Add(fullPath.ToLower(), null);
                        return(_WorkItem.AppData.CreateNewAppInfo(null, appName, fullPath, imagePath));
                        //result.Add(_WorkItem.AppData.CreateNewAppInfo(null, appName, fullPath, imagePath));
                    }
                }
            }
            else if (!onlyPrograms)            // Add folders
            {
                if (Directory.Exists(path))
                {
                    if (!uniq.ContainsKey(path.ToLower()))
                    {
                        uniq.Add(path.ToLower(), null);
                        return(_WorkItem.AppData.CreateNewAppInfo(null, path));
                        //result.Add(_WorkItem.AppData.CreateNewAppInfo(null, path));
                    }
                }
            }

            return(null);
        }