Ejemplo n.º 1
0
        public void GetText(String path, ref string text)
        // path is the path of the .doc, .xls or .ppt  file
        // text is the variable in which all the extracted text will be stored
        {
            String result = "";
            int    count  = 0;

            try
            {
                IFilter ifilt = (IFilter)(new CFilter());
                //System.Runtime.InteropServices.UCOMIPersistFile ipf = (System.Runtime.InteropServices.UCOMIPersistFile)(ifilt);
                System.Runtime.InteropServices.ComTypes.IPersistFile ipf = (System.Runtime.InteropServices.ComTypes.IPersistFile)(ifilt);
                ipf.Load(@path, 0);
                uint       i  = 0;
                STAT_CHUNK ps = new STAT_CHUNK();
                ifilt.Init(IFILTER_INIT.NONE, 0, null, ref i);
                int hr = 0;

                while (hr == 0)
                {
                    ifilt.GetChunk(out ps);
                    if (ps.flags == CHUNKSTATE.CHUNK_TEXT)
                    {
                        uint pcwcBuffer = 1000;
                        int  hr2        = 0;
                        while (hr2 == Constants.FILTER_S_LAST_TEXT || hr2 == 0)
                        {
                            try
                            {
                                pcwcBuffer = 1000;
                                System.Text.StringBuilder sbBuffer = new StringBuilder((int)pcwcBuffer);
                                hr2 = ifilt.GetText(ref pcwcBuffer, sbBuffer);
                                // Console.WriteLine(pcwcBuffer.ToString());
                                if (hr2 >= 0)
                                {
                                    result += sbBuffer.ToString(0, (int)pcwcBuffer);
                                }
                                //textBox1.Text +="\n";
                                // result += "#########################################";
                                count++;
                            }
                            catch (System.Runtime.InteropServices.COMException myE)
                            {
                                Console.WriteLine(myE.Data + "\n" + myE.Message + "\n");
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException myE)
            {
                Console.WriteLine(myE.Data + "\n" + myE.Message + "\n");
            }

            text = result;
            //return count;
            return;
        }
Ejemplo n.º 2
0
        public static void CreateLink(string pathToApplication, string description, string linkname = "MyApplication.lnk", string arguments = "")
        {
            IShellLink shortcut = (IShellLink) new ShellLink();
            string     desktop  = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            shortcut.SetDescription(description);
            shortcut.SetPath(pathToApplication);
            shortcut.SetArguments(arguments);
            shortcut.SetShowCmd(7);//SW_SHOWMINNOACTIVE
            System.Runtime.InteropServices.ComTypes.IPersistFile f = (System.Runtime.InteropServices.ComTypes.IPersistFile)shortcut;
            f.Save(Path.Combine(desktop, $"{linkname}.lnk"), false);
        }
Ejemplo n.º 3
0
        private void appShortcutToDesktop(string linkName, string pathToExe)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription(linkName);
            link.SetPath(pathToExe);
            link.SetWorkingDirectory(Path.GetDirectoryName(pathToExe));

            // save it
            System.Runtime.InteropServices.ComTypes.IPersistFile file = (System.Runtime.InteropServices.ComTypes.IPersistFile)link;
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, linkName + ".lnk"), false);
        }
Ejemplo n.º 4
0
        private async void BtnCreate_Click(object sender, RoutedEventArgs e)
        {
            if (!File.Exists(ViewModel.Path))
            {
                MessageBox.Show("文件不存在。", Title, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var fileName = FileExtension.TryValidateFileName(ViewModel.Name, out var trueName)
                ? trueName
                : Path.GetFileNameWithoutExtension(ViewModel.Path);
            var ext = Path.GetExtension(ViewModel.Path);

            if (ViewModel.UseShortcut)
            {
                IShellLink link = (IShellLink) new ShellLink();

                //link.SetDescription(fileName);
                link.SetPath(ViewModel.Path);
                System.Runtime.InteropServices.ComTypes.IPersistFile file =
                    (System.Runtime.InteropServices.ComTypes.IPersistFile)link;
                file.Save(Path.Combine(_baseConsole.RomDirectoryPath, fileName + ".lnk"), false);
            }
            else
            {
                File.Copy(ViewModel.Path, Path.Combine(_baseConsole.RomDirectoryPath, fileName + ext));
            }

            await _baseConsole.Refresh();

            var game = _baseConsole.Games.FirstOrDefault(k => k.NameWithoutExtension == fileName);

            if (File.Exists(ViewModel.IconPath))
            {
                game?.SetIcon(ViewModel.IconPath);
            }
            game?.RaisePropertyChanged(nameof(game.IconPath));
            _baseWindow.Close();
        }