public RemoteAppLib.New.FileTypeAssociation ManageFta(string defaultPath, int defaultIndex = 0, string fileType = ".xyz", bool isEdit = false)
        {
            var fta = new RemoteAppLib.New.FileTypeAssociation();

            FileTypeLabel.Visible     = true;
            FileTypeTextBox.Visible   = true;
            IconIndexLabel.Visible    = true;
            IconIndexTextBox.Visible  = true;
            IconIndexTextBox.ReadOnly = true;
            FileTypeTextBox.ReadOnly  = isEdit;

            Text = "File Type";
            FileTypeTextBox.Text  = fileType;
            IconPathTextBox.Text  = defaultPath;
            IconIndexTextBox.Text = defaultIndex.ToString();
            LoadIcons();
            if (ShowDialog() == DialogResult.OK)
            {
                fta.Extension = FileTypeTextBox.Text;
                fta.IconPath  = IconPathTextBox.Text;
                fta.IconIndex = IconIndexTextBox.Text;
            }

            //Dispose();
            return(fta);
        }
Esempio n. 2
0
        private void CreateButton_Click(object sender, EventArgs e)
        {
            if (_remoteApp.FileTypeAssociations is null)
            {
                var ftaCol = new RemoteAppLib.New.FileTypeAssociationCollection();
                _remoteApp.FileTypeAssociations = ftaCol;
            }

            _ = new RemoteAppLib.New.FileTypeAssociation();
            var fta     = Forms.RemoteAppIconPicker.ManageFta(_remoteApp.IconPath, 0);
            var sameFta = false;

            if (fta.Extension != null)
            {
                foreach (RemoteAppLib.New.FileTypeAssociation rafta in _remoteApp.FileTypeAssociations)
                {
                    if ((rafta.Extension ?? "") == (fta.Extension ?? ""))
                    {
                        sameFta = true;
                    }
                }

                if (!sameFta)
                {
                    _remoteApp.FileTypeAssociations.Add(fta);
                }
                else
                {
                    MessageBox.Show("There is already an association for filetype: " + fta.Extension, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }

            LoadFtAs();
        }
 private void ExtractFtIcon(string productFileName, RemoteAppLib.New.FileTypeAssociation fta)
 {
     // Extract icon for filetype
     if (!IconModule.ExtractToIco(fta.IconPath, int.Parse(fta.IconIndex), productFileName + "." + fta.Extension + ".ico"))
     {
         // If filetype icon fails to extract, then grab the default document icon from Shell32.dll
         IconModule.ExtractToIco(RemoteAppFunction.GetSysDir() + @"\shell32.dll", 0, productFileName + "." + fta.Extension + ".ico");
         // Possibly show an error here??
     }
 }
Esempio n. 4
0
        private void SetAssociationButton_Click(object sender, EventArgs e) // NEED TO SORT OUT EVERYTHING IN THIS SUB!!!
        {
            var fta = new RemoteAppLib.New.FileTypeAssociation
            {
                Extension = FTAListView.SelectedItems[0].SubItems[0].Text,
                IconPath  = FTAListView.SelectedItems[0].SubItems[1].Text,
                IconIndex = FTAListView.SelectedItems[0].SubItems[2].Text
            };

            if (LocalFtaModule.DoesFtaExist(fta.Extension))
            {
                DialogResult MsgBoxResult;
                // An existing association was found
                if (!LocalFtaModule.IsFtaMine(fta.Extension))
                {
                    // FTA found and belongs to another application (replace?)
                    MsgBoxResult = MessageBox.Show("An association already exists on the local computer for filetype. Would you like to replace it?" + Environment.NewLine + Environment.NewLine + "Warning: This association was created by another application. Replacing it can cause problems. If the existing association is working, there is no need to replace it.", "File Type Association", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                    if (MsgBoxResult == DialogResult.Yes)
                    {
                        LocalFtaModule.CreateFta(fta, _remoteApp.Path, _remoteApp.Name, true);
                    }
                }
                else
                {
                    // FTA found and belongs to RemoteApp Tool (remove)
                    MsgBoxResult = MessageBox.Show("Are you sure you want to remove this file type association on the local computer?", "File Type Association", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                    if (MsgBoxResult == DialogResult.Yes)
                    {
                        LocalFtaModule.DeleteFta(fta.Extension);
                    }
                }
            }
            // FTA not found (create)
            else if (LocalFtaModule.CreateFta(fta, _remoteApp.Path, _remoteApp.Name))
            {
                MessageBox.Show("File type association created for " + fta.Extension + ".", "File Type Association", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("File type association not created. There was an error.", "File Type Association", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            LoadFtAs();
        }
Esempio n. 5
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            var FileType = FTAListView.SelectedItems[0].Text;

            if (MessageBox.Show("Are you sure you want to remove filetype:" + Environment.NewLine + "." + FileType + " ?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                _ = FTAListView.SelectedItems[0].SubItems[0].Text;
                _ = FTAListView.SelectedItems[0].SubItems[1].Text;
                var ftAtoRemove = new RemoteAppLib.New.FileTypeAssociation();
                foreach (RemoteAppLib.New.FileTypeAssociation fta in _remoteApp.FileTypeAssociations)
                {
                    if ((fta.Extension ?? "") == (FileType ?? ""))
                    {
                        ftAtoRemove = fta;
                    }
                }

                _remoteApp.FileTypeAssociations.Remove(ftAtoRemove);
            }

            LoadFtAs();
        }
Esempio n. 6
0
        private void EditFta()
        {
            _ = new RemoteAppLib.New.FileTypeAssociation();
            var fta = Forms.RemoteAppIconPicker.ManageFta(FTAListView.SelectedItems[0].SubItems[1].Text, (int)Math.Round(double.Parse(FTAListView.SelectedItems[0].SubItems[2].Text)), FTAListView.SelectedItems[0].Text, true);

            if (fta.Extension != null)
            {
                _ = FTAListView.SelectedItems[0].SubItems[0].Text;
                _ = FTAListView.SelectedItems[0].SubItems[1].Text;
                var FileType    = FTAListView.SelectedItems[0].Text;
                var ftAtoRemove = new RemoteAppLib.New.FileTypeAssociation();
                foreach (RemoteAppLib.New.FileTypeAssociation fta2 in _remoteApp.FileTypeAssociations)
                {
                    if ((fta2.Extension ?? "") == (FileType ?? ""))
                    {
                        ftAtoRemove = fta2;
                    }
                }

                _remoteApp.FileTypeAssociations.Remove(ftAtoRemove);
                _remoteApp.FileTypeAssociations.Add(fta);
                LoadFtAs();
            }
        }