Ejemplo n.º 1
0
        private void AppsBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedApp = (sender as ComboBox)?.SelectedItem?.ToString();

            SelectedAppData = CacheData.FindAppData(selectedApp);
            if (SelectedAppData?.Name?.EqualsEx(selectedApp) != true)
            {
                return;
            }

            fileTypes.Text = SelectedAppData.Settings.FileTypes.Join(',');

            var restPointDir = Path.Combine(CorePaths.RestorePointDir, SelectedAppData.Key);

            restoreFileTypesBtn.Enabled = Directory.Exists(restPointDir) && DirectoryEx.EnumerateFiles(restPointDir, "*.dat", SearchOption.AllDirectories)?.Any() == true;
            restoreFileTypesBtn.Visible = restoreFileTypesBtn.Enabled;

            startArgsFirst.Text = SelectedAppData.Settings.StartArgsFirst;
            startArgsLast.Text  = SelectedAppData.Settings.StartArgsLast;

            sortArgPathsCheck.Checked = SelectedAppData.Settings.SortArgPaths;
            noConfirmCheck.Checked    = SelectedAppData.Settings.NoConfirm;
            runAsAdminCheck.Checked   = SelectedAppData.Settings.RunAsAdmin;
            noUpdatesCheck.Checked    = SelectedAppData.Settings.NoUpdates;
        }
Ejemplo n.º 2
0
        private void FileTypesMenu_Click(object sender, EventArgs e)
        {
            switch ((sender as ToolStripMenuItem)?.Name)
            {
            case nameof(fileTypesMenuItem1):
                if (!string.IsNullOrEmpty(fileTypes.SelectedText))
                {
                    Clipboard.SetText(fileTypes.SelectedText);
                }
                break;

            case nameof(fileTypesMenuItem2):
                if (Clipboard.ContainsText())
                {
                    if (string.IsNullOrEmpty(fileTypes.SelectedText))
                    {
                        var start = fileTypes.SelectionStart;
                        fileTypes.Text           = fileTypes.Text.Insert(start, Clipboard.GetText());
                        fileTypes.SelectionStart = start + Clipboard.GetText().Length;
                    }
                    else
                    {
                        fileTypes.SelectedText = Clipboard.GetText();
                    }
                }
                break;

            case nameof(fileTypesMenuItem3):
                var selectedItem = appsBox.SelectedItem.ToString();
                if (!string.IsNullOrEmpty(selectedItem))
                {
                    var appData = CacheData.FindAppData(selectedItem);
                    if (appData != default)
                    {
                        var iniPath = appData.AppInfoPath;
                        if (!File.Exists(iniPath))
                        {
                            iniPath = appData.ConfigPath;
                        }
                        if (!File.Exists(iniPath))
                        {
                            iniPath = DirectoryEx.EnumerateFiles(appData.FileDir, "*.ini").LastOrDefault();
                        }
                        if (File.Exists(iniPath))
                        {
                            var types = Ini.Read("Associations", "FileTypes", iniPath);
                            if (!string.IsNullOrWhiteSpace(types))
                            {
                                fileTypes.Text = types.RemoveChar(' ');
                                return;
                            }
                        }
                    }
                }
                MessageBoxEx.Show(this, Language.GetText(nameof(en_US.NoDefaultTypesFoundMsg)), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                break;
            }
        }
Ejemplo n.º 3
0
        internal static List <string> FindAppInstaller()
        {
            var appInstaller  = new List <string>();
            var searchPattern = new[]
            {
                "*.7z",
                "*.rar",
                "*.zip",
                "*.paf.exe"
            };

            if (Directory.Exists(Settings.TransferDir))
            {
                appInstaller.AddRange(searchPattern.SelectMany(x => DirectoryEx.EnumerateFiles(Settings.TransferDir, x)));
            }
            return(appInstaller);
        }
Ejemplo n.º 4
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     using (var dialog = new OpenFileDialog
     {
         Filter = @"Icon files (*.ico)|*.ico",
         CheckFileExists = true,
         CheckPathExists = true,
         Multiselect = false
     })
         try
         {
             if (dialog.ShowDialog(this) != DialogResult.OK)
             {
                 Application.Exit();
                 return;
             }
             var file = dialog.FileName;
             var dir  = Path.GetDirectoryName(file);
             if (string.IsNullOrEmpty(dir))
             {
                 throw new ArgumentNullException(nameof(dir));
             }
             var name = Path.GetFileNameWithoutExtension(file);
             if (string.IsNullOrEmpty(name))
             {
                 throw new ArgumentNullException(nameof(name));
             }
             dir = Path.Combine(dir, $"{name} sources");
             IconFactory.Extract(dialog.FileName);
             if (!Directory.Exists(dir))
             {
                 throw new PathNotFoundException(dir);
             }
             if (DirectoryEx.EnumerateFiles(dir, "*.png")?.Any() != true)
             {
                 throw new FileNotFoundException();
             }
             Process.Start(dir);
         }
         catch (Exception ex)
         {
             Log.Write(ex);
         }
     Application.Exit();
 }
Ejemplo n.º 5
0
        internal static bool AppIsInstalled(AppData appData)
        {
            var dir = appData.InstallDir;

            if (!Directory.Exists(dir))
            {
                return(false);
            }
            const string pattern = "*.exe";

            switch (appData.Key)
            {
            case "Ghostscript":
            case "Java":
            case "Java64":
            case "JDK":
            case "JDK64":
            case "OpenJDK":
            case "OpenJDK64":
            case "OpenJDKJRE":
            case "OpenJDKJRE64":
                dir = Path.Combine(dir, "bin");
                if (DirectoryEx.EnumerateFiles(dir, pattern).Any())
                {
                    return(true);
                }
                break;

            default:
                if (DirectoryEx.EnumerateFiles(dir, pattern).Any())
                {
                    return(true);
                }
                var iniName = $"{appData.Key}.ini";
                if (DirectoryEx.EnumerateFiles(dir, iniName).Any() &&
                    DirectoryEx.EnumerateFiles(dir, pattern, SearchOption.AllDirectories).Any())
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
        public void Import()
        {
            Log.Info("Import started...");

            _store.ClearCollection("MediaItems");

            int succeeded = 0;
            int failed    = 0;

            using (BulkInsertOperation bulkInsert = _store.BulkInsert())
            {
                var files = DirectoryEx.EnumerateFiles(_watchFolder, _watchExtensions, SearchOption.AllDirectories);
                foreach (var file in files)
                {
                    try
                    {
                        var mediaItem = _mediaItemFactory.Create(file);
                        if (mediaItem != null)
                        {
                            bulkInsert.Store(mediaItem);
                            succeeded++;

                            if (Log.IsDebugEnabled)
                            {
                                Log.DebugFormat("File indexed: {0}", file);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        failed++;
                        Log.ErrorFormat("Failed indexing file: {0}. {1}", file, ex.Message);
                    }
                }
            }

            Log.InfoFormat("Import finished. Succeeded: {0}. Failed: {1}", succeeded, failed);
        }
Ejemplo n.º 7
0
 /// <summary>
 ///     Extracts all the <see cref="Image"/>'s from a valid icon file.
 /// </summary>
 /// <param name="path">
 ///     The full path to the icon to be extracted.
 /// </param>
 public static void Extract(string path)
 {
     try
     {
         var file = PathEx.Combine(path);
         if (!File.Exists(file))
         {
             throw new PathNotFoundException(file);
         }
         var dir = Path.GetDirectoryName(file);
         if (string.IsNullOrEmpty(dir))
         {
             throw new ArgumentNullException(nameof(dir));
         }
         var name = Path.GetFileNameWithoutExtension(file);
         if (string.IsNullOrEmpty(name))
         {
             throw new ArgumentNullException(nameof(name));
         }
         dir = Path.Combine(dir, $"{name} sources");
         if (Directory.Exists(dir))
         {
             DirectoryEx.EnumerateFiles(dir, "*.png")?.ForEach(x => FileEx.Delete(x));
         }
         else
         {
             Directory.CreateDirectory(dir);
         }
         var buffer = File.ReadAllBytes(file);
         var length = BitConverter.ToInt16(buffer, 4);
         for (var i = 0; i < length; i++)
         {
             var imageWidth  = buffer[SizeIconDir + SizeIconDirEntry * i];
             var imageHeight = buffer[SizeIconDir + SizeIconDirEntry * i + 1];
             var pixelFormat = (int)BitConverter.ToInt16(buffer, SizeIconDir + SizeIconDirEntry * i + 6);
             var imagePath   = Path.Combine(dir, $"{pixelFormat}@{imageWidth}x{imageHeight}.png");
             if (File.Exists(imagePath))
             {
                 for (var j = 0; j < byte.MaxValue; j++)
                 {
                     if (!File.Exists(imagePath))
                     {
                         break;
                     }
                     imagePath = Path.Combine(dir, $"{pixelFormat}@{imageWidth}x{imageHeight}_{i}.png");
                 }
             }
             var formatSize = BitConverter.ToInt32(buffer, SizeIconDir + SizeIconDirEntry * i + 8);
             var offset     = BitConverter.ToInt32(buffer, SizeIconDir + SizeIconDirEntry * i + 12);
             var ms         = default(MemoryStream);
             try
             {
                 ms = new MemoryStream();
                 using (var bw = new BinaryWriter(ms))
                 {
                     bw.Write(buffer, offset, formatSize);
                     ms.Seek(0, SeekOrigin.Begin);
                     using (var bmp = new Bitmap(ms))
                     {
                         ms = null;
                         bmp.Save(imagePath);
                     }
                 }
             }
             finally
             {
                 ms?.Dispose();
             }
         }
     }
     catch (Exception ex) when(ex.IsCaught())
     {
         Log.Write(ex);
     }
 }