GetExtension() private méthode

private GetExtension ( string path ) : string
path string
Résultat string
Exemple #1
0
        public void Load()
        {
            var dialog = new FolderBrowserDialog();

            dialog.ShowNewFolderButton = false;
            var    res           = dialog.ShowDialog();
            string directoryName = null;

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                directoryName = dialog.SelectedPath;
            }
            if (directoryName == null)
            {
                return;
            }
            var    filesName   = new List <string>(Directory.GetFiles(directoryName));
            string inkFileName = null;

            foreach (var fileName in filesName)
            {
                if (!fileName.Contains("_ink.xaml") || !Path.GetExtension(fileName).Equals(".xaml"))
                {
                    continue;
                }
                inkFileName = fileName;
                break;
            }
            if (inkFileName == null)
            {
                return;
            }
            LoadInkCanvas(inkFileName, filesName);
            LoadChild(filesName);
        }
Exemple #2
0
        private void Rename_Click(object sender, RoutedEventArgs e)
        {
            if (_videosFilesNames.IsNullOrEmpty() || _subtitlesFilesNames.IsNullOrEmpty())
            {
                MessageBox.Show("Make Sure that the lists contain files");
            }
            else if (_videosFilesNames.Length != _subtitlesFilesNames.Length)
            {
                MessageBox.Show("The Number of videos and subtitles must be equal");
            }
            else
            {
                try
                {
                    for (int i = 0; i < _videosFilesNames.Length; i++)
                    {
                        var directoryName           = Path.GetDirectoryName(_videosFilesNames[i]);
                        var vidNameWithoutExtension = Path.GetFileNameWithoutExtension(_videosFilesNames[i]);
                        var subtitleExtenstion      = Path.GetExtension(_subtitlesFilesNames[i]);
                        var newSubtitleName         = string.Concat(directoryName, @"\", vidNameWithoutExtension,
                                                                    subtitleExtenstion);
                        File.Move(_subtitlesFilesNames[i], newSubtitleName);
                    }

                    MessageBox.Show("Files are Renamed Successfully");
                    ClearVideoList();
                    ClearSubtitlesList();
                }

                catch
                {
                    MessageBox.Show("Something Wrong Happened");
                }
            }
        }
Exemple #3
0
        private void LoadFile(string fileName)
        {
            string lowerFilename = Path.GetExtension(fileName).ToLower();

            if (lowerFilename.EndsWith(".pcc") || lowerFilename.EndsWith(".u") || lowerFilename.EndsWith(".sfm") || lowerFilename.EndsWith(".upk"))
            {
                pcc = MEPackageHandler.OpenMEPackage(fileName);
            }
            else if (lowerFilename.EndsWith(".sfar"))
            {
                dlcPackage = new DLCPackage(fileName);
            }

            bytes = File.ReadAllBytes(fileName);
            Interpreter_Hexbox.ByteProvider = new DynamicByteProvider(bytes);
            Title = "FileHexViewerWPF - " + fileName;
            AddRecent(fileName, false);
            SaveRecentList();
            RefreshRecent();
            MemoryStream inStream = new MemoryStream(bytes);

            UnusedSpaceList.ClearEx();
            if (pcc != null)
            {
                parsePackage(inStream);
            }
            else if (dlcPackage != null)
            {
                parseDLC(inStream);
            }
        }
Exemple #4
0
 private void Encrypt_Click(object sender, RoutedEventArgs e)
 {
     foreach (string item in File2.GetDirectories(root: "", path, rootDir + Global.DownloadFolder))
     {
         if (File.Exists($"{item}/info.json"))
         {
             JObject j = JObject.Parse(File.ReadAllText($"{item}/info.json"));
             j["encrypted"] = true;
             File.WriteAllText($"{item}/info.json", j.ToString());
         }
         string[] files = Directory.GetFiles(item);
         foreach (string file in files)
         {
             if (Path.GetFileName(file) == "info.json")
             {
                 continue;
             }
             if (Path.GetFileName(file) == "info.txt")
             {
                 continue;
             }
             if (Path.GetExtension(file) == ".lock")
             {
                 continue;
             }
             byte[] org = File.ReadAllBytes(file);
             byte[] enc = FileEncrypt.Default(org);
             File.Delete(file);
             File.WriteAllBytes(file + ".lock", enc);
         }
     }
     MessageBox.Show("전체 암호화 완료");
 }
Exemple #5
0
        private void DestinationEditBoxGotFocus(object sender, RoutedEventArgs e)
        {
            this.outputVM.EditingDestination = true;

            string path     = this.outputVM.OutputPath;
            string fileName = Path.GetFileName(path);

            if (fileName == string.Empty)
            {
                this.destinationEditBox.Select(path.Length, 0);
            }
            else
            {
                int selectStart = path.Length - fileName.Length;

                string extension = Path.GetExtension(path);
                if (extension == string.Empty)
                {
                    this.destinationEditBox.Select(selectStart, path.Length - selectStart);
                }
                else
                {
                    this.destinationEditBox.Select(selectStart, path.Length - selectStart - extension.Length);
                }
            }

            this.outputVM.OldOutputPath = this.outputVM.OutputPath;
        }
Exemple #6
0
        public override void _ExportFile(string path, string type, string[] features)
        {
            base._ExportFile(path, type, features);

            if (type != Internal.CSharpLanguageType)
            {
                return;
            }

            if (Path.GetExtension(path) != $".{Internal.CSharpLanguageExtension}")
            {
                throw new ArgumentException($"Resource of type {Internal.CSharpLanguageType} has an invalid file extension: {path}", nameof(path));
            }

            // TODO What if the source file is not part of the game's C# project

            bool includeScriptsContent = (bool)ProjectSettings.GetSetting("mono/export/include_scripts_content");

            if (!includeScriptsContent)
            {
                // We don't want to include the source code on exported games
                AddFile(path, new byte[] { }, remap: false);
                Skip();
            }
        }
        //public static MediaType MediaTypeFromFileName(string fullPath)
        //{
        //    string extNoDot = Path.GetExtension(fullPath).Remove(0, 1);
        //    if (Enum.GetNames(typeof(ExtensionsImages)).Contains<string>(extNoDot))
        //    {
        //        return MediaType.Image;
        //    }
        //    else if (Enum.GetNames(typeof(ExtensionsMovies)).Contains<string>(extNoDot))
        //    {
        //        return MediaType.Movie;
        //    }
        //    else if (Enum.GetNames(typeof(ExtensionsAudio)).Contains<string>(extNoDot))
        //    {
        //        return MediaType.Audio;
        //    }
        //    return MediaType.Unknown;
        //}

        public static MediaType MediaTypeFromFileName(string fullPath)
        {
            string extension = Path.GetExtension(fullPath);

            if (extension == null || extension.Length == 0)
            {
                return(MediaType.Unknown);
            }
            string extNoDot = extension.Remove(0, 1);
            var    mi       = new MediaInfoDotNet.MediaFile(fullPath);

            //if (mi.Image.Count > 0 || mi.General.InternetMediaType.Contains("image"))
            if (Helpers.GetTrimmedSplitStringList(Properties.Settings.Default.extensionsImage).Contains <string>(extNoDot))
            //if (Helpers.GetTrimmedSplitStringList(MainWindow.ExtensionsImages).Contains<string>(extNoDot))
            {
                return(MediaType.Image);
            }
            else if (Helpers.GetTrimmedSplitStringList(Properties.Settings.Default.extensionsVideo).Contains <string>(extNoDot))
            //else if (Helpers.GetTrimmedSplitStringList(MainWindow.ExtensionsVideo).Contains<string>(extNoDot))
            //if (mi.Video.Count > 0 || mi.General.InternetMediaType.Contains("video"))
            {
                return(MediaType.Movie);
            }
            else if (Helpers.GetTrimmedSplitStringList(Properties.Settings.Default.extensionsAudio).Contains <string>(extNoDot))
            //else if (Helpers.GetTrimmedSplitStringList(MainWindow.ExtensionsAudio).Contains<string>(extNoDot))
            //if (mi.Audio.Count > 0 || mi.General.InternetMediaType.Contains("audio"))
            {
                return(MediaType.Audio);
            }
            return(MediaType.Unknown);
        }
        /// <summary>
        /// Recursively traverses the tree and adds all checked items, which are files to the FileList
        /// </summary>
        /// <param name="parentContainer"></param>
        private void GetNextContainer(MyTreeViewItem parentContainer)
        {
            foreach (var item in parentContainer.Items)
            {
                MyTreeViewItem currentContainer = parentContainer.ItemContainerGenerator.ContainerFromItem(item) as MyTreeViewItem;

                if (currentContainer == null)
                {
                    continue;
                }
                if (currentContainer.IsChecked != null && currentContainer.IsChecked == true && currentContainer.FileType == File)
                {
                    var addFile = myPresenter.PathAllreadyInList(currentContainer.Tag.ToString(), _fileCollection);
                    if (addFile)
                    {
                        //ListViewSelectedFiles.Items.Add(currentContainer.Tag);
                        var add    = new FileItem();
                        var myInfo = new FileInfo(currentContainer.Tag.ToString());
                        add.FullPath = currentContainer.Tag.ToString();
                        add.Name     = Path.GetFileNameWithoutExtension(currentContainer.Header.ToString());
                        double len = myInfo.Length;
                        add.Size    = myPresenter.MakeFileSizeToReadableString(len);
                        add.Changed = myInfo.LastWriteTime.ToString(CultureInfo.InvariantCulture);
                        add.Type    = Path.GetExtension(add.FullPath).Length > 0 ? Path.GetExtension(add.FullPath).Substring(1) : "Unknown";
                        _fileCollection.Files.Add(add);
                    }
                }
                // If the sub containers of current item is ready, we can directly go to the next
                // iteration to expand them.
                GetNextContainer(currentContainer);
            }
        }
Exemple #9
0
 private void PopulateRecentFiles(bool singleFile = false)
 {
     if (!singleFile)
     {
         var folderPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FloorPlanner");
         if (!Directory.Exists(folderPath))
         {
             Directory.CreateDirectory(folderPath);
         }
         DirectoryInfo info  = new DirectoryInfo(folderPath);
         FileInfo[]    files = info.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray();
         foreach (var file in files)
         {
             string extension        = IOPath.GetExtension(file.Name);
             string recentFileName   = file.Name.Substring(0, file.Name.Length - extension.Length);
             var    recentFileButton = new RecentFileButton()
             {
                 FileName = recentFileName, FolderPath = folderPath, Command = OpenCommand
             };
             this.View.RecentArea.Children.Add(recentFileButton);
         }
     }
     else
     {
         var recentFileButton = new RecentFileButton()
         {
             FileName = this.selectedFileName, FolderPath = this.selectedFolderPath, Command = OpenCommand
         };
         this.View.RecentArea.Children.Insert(0, recentFileButton);
     }
 }
        void AddFileAsItem(string filePath)
        {
            string resourceType = FileExtension.FileExtensionToType(IOPath.GetExtension(filePath)).AssemblyQualifiedName;
            string resourceName = IOPath.GetFileNameWithoutExtension(filePath);

            AddItem(new ResXDataNode(resourceName, new ResXFileRef(filePath, resourceType)));
        }
Exemple #11
0
        public static string ChangeExtension(string path, string ext)
        {
            string e = Path.GetExtension(path);

            if (string.IsNullOrEmpty(e))
            {
                return(path + ext);
            }

            bool backDSC = path.IndexOf('\\') != -1;

            path = path.Replace('\\', '/');
            if (path.IndexOf('/') == -1)
            {
                return(path.Substring(0, path.LastIndexOf('.')) + ext);
            }

            string dir  = path.Substring(0, path.LastIndexOf('/'));
            string name = path.Substring(path.LastIndexOf('/'), path.Length - path.LastIndexOf('/'));

            name = name.Substring(0, name.LastIndexOf('.')) + ext;
            path = dir + name;

            if (backDSC)
            {
                path = path.Replace('/', '\\');
            }
            return(path);
        }
Exemple #12
0
        public T ReadObject <T>(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(nameof(filePath), "File path cannot be null or empty.");
            }

            string extension = PathType.GetExtension(filePath);

            if (string.IsNullOrEmpty(extension))
            {
                throw new ArgumentException(nameof(filePath), "The file requires an extension.");
            }

            if (SerializationFormats.TryGetValue(extension, out var format) && format != null)
            {
                using (var stream = OpenFile(filePath, FileMode.Open, FileAccess.Read))
                {
                    try
                    {
                        return(format.Read <T>(stream));
                    }
                    catch (Exception ex)
                    {
                        throw new SerializationFailException($"Could not read the file using {format.GetType().Name}.", ex);
                    }
                }
            }
            else
            {
                throw new UnknownSerializationFormatException($"Cannot read an object from a {extension} file.");
            }
        }
Exemple #13
0
        public void WriteObject <T>(string filePath, T data)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(nameof(filePath), "File path cannot be null or empty.");
            }

            string extension = PathType.GetExtension(filePath);

            if (string.IsNullOrEmpty(extension))
            {
                throw new ArgumentException(nameof(filePath), "The file requires an extension.");
            }

            if (SerializationFormats.TryGetValue(extension, out var format) && format != null)
            {
                using (var stream = OpenFile(filePath, FileMode.Create, FileAccess.Write))
                {
                    try
                    {
                        format.Write <T>(stream, data);
                    }
                    catch (Exception ex)
                    {
                        throw new SerializationFailException($"Could not write the file using {format.GetType().Name}.", ex);
                    }
                }
            }
            else
            {
                throw new UnknownSerializationFormatException($"Cannot write an object to a {extension} file.");
            }
        }
        private static Coercion Coerce(string path)
        {
            if (!File.Exists(path))
            {
                var fileNameWithoutScriptExtension   = IOPath.GetFileNameWithoutExtension(path);
                var fileNameWithoutAssemblyExtension = IOPath.GetFileNameWithoutExtension(fileNameWithoutScriptExtension);
                if (fileNameWithoutAssemblyExtension.EndsWith(visualStudioHostSuffix, StringComparison.OrdinalIgnoreCase))
                {
                    var fileNameWithoutHostSuffix = string.Concat(
                        fileNameWithoutAssemblyExtension.Substring(
                            0, fileNameWithoutAssemblyExtension.Length - visualStudioHostSuffixLength),
                        IOPath.GetExtension(fileNameWithoutScriptExtension),
                        IOPath.GetExtension(path));

                    var pathWithoutHostSuffix = IOPath.Combine(IOPath.GetDirectoryName(path), fileNameWithoutHostSuffix);
                    if (File.Exists(pathWithoutHostSuffix))
                    {
                        return(new Coercion {
                            Path = pathWithoutHostSuffix, Occurred = true
                        });
                    }
                }
            }

            return(new Coercion {
                Path = path, Occurred = false
            });
        }
        private void ButtonOpen_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "doc files (*.doc)|*.doc|Text Files (*.txt)|*.txt|XAML Files (*.xaml)|*.xaml|All files (*.*)|*.*";

            if (ofd.ShowDialog() == true)
            {
                TextRange doc = new TextRange(rich.Document.ContentStart, rich.Document.ContentEnd);
                using (FileStream fs = new FileStream(ofd.FileName, FileMode.Open))
                {
                    if (Path.GetExtension(ofd.FileName).ToLower() == ".txt")
                    {
                        doc.Load(fs, DataFormats.Text);
                    }
                    else if (Path.GetExtension(ofd.FileName).ToLower() == ".doc")
                    {
                        doc.Load(fs, DataFormats.Text);
                    }


                    else
                    {
                        doc.Load(fs, DataFormats.Xaml);
                    }
                }
            }
        }
Exemple #16
0
        private static void WriteDiagnosticResults(ImmutableArray <Tuple <ProjectId, Diagnostic> > diagnostics, string fileName)
        {
            var orderedDiagnostics =
                diagnostics
                .OrderBy(tuple => tuple.Item2.Id)
                .ThenBy(tuple => tuple.Item2.Location.SourceTree?.FilePath, StringComparer.OrdinalIgnoreCase)
                .ThenBy(tuple => tuple.Item2.Location.SourceSpan.Start)
                .ThenBy(tuple => tuple.Item2.Location.SourceSpan.End);

            var           uniqueLines    = new HashSet <string>();
            StringBuilder completeOutput = new StringBuilder();
            StringBuilder uniqueOutput   = new StringBuilder();

            foreach (var diagnostic in orderedDiagnostics)
            {
                string message       = diagnostic.Item2.ToString();
                string uniqueMessage = $"{diagnostic.Item1}: {diagnostic.Item2}";
                completeOutput.AppendLine(message);
                if (uniqueLines.Add(uniqueMessage))
                {
                    uniqueOutput.AppendLine(message);
                }
            }

            string directoryName            = Path.GetDirectoryName(fileName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            string extension      = Path.GetExtension(fileName);
            string uniqueFileName = Path.Combine(directoryName, $"{fileNameWithoutExtension}-Unique{extension}");

            File.WriteAllText(fileName, completeOutput.ToString(), Encoding.UTF8);
            File.WriteAllText(uniqueFileName, uniqueOutput.ToString(), Encoding.UTF8);
        }
        private bool ShouldIgnore(string filepath)
        {
            string fDir  = Path.GetDirectoryName(filepath);
            string fName = Path.GetFileNameWithoutExtension(filepath);
            string fExt  = Path.GetExtension(filepath);

            if (HideHidden)
            {
                if (fName.Length == 0)
                {
                    return(true);
                }
                if (fName[0] == '.')
                {
                    return(true);
                }
            }
            if (IgnoreTextBox.Text.Length != 0)
            {
                if (fName.Contains(IgnoreTextBox.Text))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #18
0
        public static Image LoadImageToBitmap(string fullname)
        {
            string extension = Path.GetExtension(fullname).ToUpper();

            if (!Filter.ExtensionsList.Contains(extension))
            {
                return(null);
            }
            Image image = null;

            string[] simpleFormats = new string[] { "*.BMP", ".DIB", ".RLE", ".GIF", ".JPG", ".PNG", ".JPEG" };

            if (simpleFormats.Contains(extension))
            {
                using (MemoryStream memory = new MemoryStream())
                    using (FileStream fs = new FileStream(fullname, FileMode.Open, FileAccess.ReadWrite))
                        image = Image.FromStream(fs);
            }
            else
            {
                using (var img = LoadImage(new FileInfo(fullname)))
                    image = ConvertToBitmap(img);
            }
            return(image);
        }
Exemple #19
0
        public bool GetAocDataStorage(ulong aocTitleId, out IStorage aocStorage, IntegrityCheckLevel integrityCheckLevel)
        {
            aocStorage = null;

            if (_aocData.TryGetValue(aocTitleId, out AocItem aoc) && aoc.Enabled)
            {
                var file = new FileStream(aoc.ContainerPath, FileMode.Open, FileAccess.Read);
                using var ncaFile = new UniqueRef <IFile>();
                PartitionFileSystem pfs;

                switch (Path.GetExtension(aoc.ContainerPath))
                {
                case ".xci":
                    pfs = new Xci(_virtualFileSystem.KeySet, file.AsStorage()).OpenPartition(XciPartitionType.Secure);
                    pfs.OpenFile(ref ncaFile.Ref(), aoc.NcaPath.ToU8Span(), OpenMode.Read);
                    break;

                case ".nsp":
                    pfs = new PartitionFileSystem(file.AsStorage());
                    pfs.OpenFile(ref ncaFile.Ref(), aoc.NcaPath.ToU8Span(), OpenMode.Read);
                    break;

                default:
                    return(false);    // Print error?
                }

                aocStorage = new Nca(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage()).OpenStorage(NcaSectionType.Data, integrityCheckLevel);

                return(true);
            }

            return(false);
        }
 private void Encrypt_Click(object sender, RoutedEventArgs e)
 {
     string[] files = Directory.GetFiles(h.dir);
     foreach (string file in files)
     {
         if (Path.GetFileName(file) == "info.json")
         {
             continue;
         }
         if (Path.GetFileName(file) == "info.txt")
         {
             continue;
         }
         if (Path.GetExtension(file) == ".lock")
         {
             continue;
         }
         byte[] org = File.ReadAllBytes(file);
         byte[] enc = FileEncrypt.Default(org);
         File.Delete(file);
         File.WriteAllBytes(file + ".lock", enc);
     }
     h.files     = h.files.Select(x => x + ".lock").ToArray();
     h.encrypted = true;
     Process.Start(h.dir);
 }
        private void logC_bt_Click(object sender, RoutedEventArgs e)
        {
            int    count       = 1;
            string dateTime    = DateTime.Now.ToString("MM-dd-yyyy h-mm tt");
            var    pathWithEnv = @"%USERPROFILE%\Appdata\roaming";
            var    fileTXT     = Environment.ExpandEnvironmentVariables(pathWithEnv + @"\vddl\logs\");
            string fileName    = fileTXT + dateTime + ".txt";

            Console.WriteLine("[VDDL] Creating Log File at: " + fileName);
            if (!File.Exists(fileName))
            {
                File.AppendAllText(fileName, txtConsole.Text);
            }
            else
            {
                string fileNameOnly = Path.GetFileNameWithoutExtension(fileName);
                string extension    = Path.GetExtension(fileName);
                string path         = Path.GetDirectoryName(fileName);
                string newFullPath  = fileName;

                while (File.Exists(newFullPath))
                {
                    string tempFileName = string.Format("{0}({1})", fileNameOnly, count++);
                    newFullPath = Path.Combine(path, tempFileName + extension);
                }
                File.AppendAllText(newFullPath, txtConsole.Text);
            }
        }
Exemple #22
0
        /// <summary>
        /// <see cref="LoadBitmapFromFile"/>
        /// </summary>
        public static bool TryLoadBitmapFromFile(string path, out Bitmap bitmap, int?width = null, int?height = null)
        {
            try
            {
                if (Path.GetExtension(path) == ".svg")
                {
                    bitmap = width.HasValue && height.HasValue
                        ? GetBitmapFromSvg(path, width.Value, height.Value)
                        : GetBitmapFromSvg(path);
                    return(true);
                }

                bitmap = width.HasValue && height.HasValue
                        ? GetBitmapFromFile(path, width.Value, height.Value)
                        : GetBitmapFromFile(path);
                return(true);
            }
            catch (Exception e) when(e is ArgumentException || e is IOException)
            {
                var image = width.HasValue && height.HasValue
                    ? new Bitmap(width.Value, height.Value)
                    : new Bitmap(100, 100);

                bitmap = ConvertBitmapToPixelFormat_32bppArgb(image);
                return(false);
            }
        }
        /// <summary>
        /// The append image.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="name">The name.</param>
        private void AppendImage(string source, string name)
        {
            // http://msdn.microsoft.com/en-us/library/bb497430.aspx
            var ext = (Path.GetExtension(source) ?? string.Empty).ToLower();
            var ipt = ImagePartType.Jpeg;

            if (ext == ".png")
            {
                ipt = ImagePartType.Png;
            }

            var imagePart = this.mainPart.AddImagePart(ipt);

            using (var stream = new FileStream(source, FileMode.Open))
            {
                imagePart.FeedData(stream);
            }

            using (var bmp = new Bitmap(source))
            {
                double width  = bmp.Width / bmp.HorizontalResolution; // inches
                double height = bmp.Height / bmp.VerticalResolution;  // inches
                double w      = 15 / 2.54;
                double h      = height / width * w;
                this.body.AppendChild(this.CreateImageParagraph(this.mainPart.GetIdOfPart(imagePart), name, source, w, h));
            }
        }
Exemple #24
0
        /// <summary>If the specified file exists it will be renamed to the next available name by adding an incrementing number to the end of it. Returns null if the file does not exist.</summary>
        public static String ReplaceFile(String path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            String dir = Path.GetDirectoryName(path);
            String nom = Path.GetFileNameWithoutExtension(path);
            String ext = Path.GetExtension(path);

            String old = path;

            Int32 i = 1;

            while (File.Exists(path))
            {
                path  = Path.Combine(dir, nom);
                path += " (" + i++ + ")";
                path += ext;
            }

            File.Move(old, path);

            return(path);
        }
Exemple #25
0
        private void BtPreview_Click(object sender, RoutedEventArgs e)
        {
            var movieFiles = Directory.GetFiles(_currentDirectory, "*" + Path.GetExtension(_currentDirectory + "\\" + TbMovie.Text));
            var srtFiles   = Directory.GetFiles(_currentDirectory, "*" + Path.GetExtension(_currentDirectory + "\\" + TbSrt.Text));
            var newRegex   = new Regex(Regex.Escape(_moviePattern).Replace("\\{", "{").Replace("\\}", "}").Replace("{0}", "([^A-Za-z]*)"));

            ListView.Visibility   = Visibility.Visible;
            PbProgress.Visibility = Visibility.Visible;
            PbProgress.Minimum    = 1;
            PbProgress.Maximum    = movieFiles.Length;
            PbProgress.Value      = 1;

            foreach (var movieFile in movieFiles)
            {
                PbProgress.Value += 1;
                var season  = newRegex.Match(Path.GetFileName(movieFile).Replace("(", "").Replace(")", "").Replace(".", " ")).Groups[1].Value.Trim();
                var episode =
                    newRegex.Match(Path.GetFileName(movieFile).Replace("(", "").Replace(")", "").Replace(".", " ")).Groups[2].Value.Trim();


                var subfile = srtFiles.FirstOrDefault(m => Path.GetFileName(m).Contains(string.Format(_subPattern, season, episode)));
                if (subfile == null)
                {
                    continue;
                }
                var newFileName = _currentDirectory + "\\" + Path.GetFileNameWithoutExtension(movieFile) + Path.GetExtension(subfile);

                ListView.Items.Add(new { Name = Path.GetFileName(subfile) + "-->" + Path.GetFileName(newFileName) });
            }
        }
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (saveCheck == false)
     {
         var result = MessageBox.Show("Сохранить файл?", "Сохранение файла", MessageBoxButton.YesNo);
         if (result == MessageBoxResult.Yes)
         {
             saveCheck = true;
             SaveFileDialog sfd = new SaveFileDialog();
             sfd.Filter = "doc files (*.doc)|*.doc|Text Files (*.txt)|*.txt|XAML Files (*.xaml)|*.xaml|All files (*.*)|*.*";
             if (sfd.ShowDialog() == true)
             {
                 TextRange doc = new TextRange(rich.Document.ContentStart, rich.Document.ContentEnd);
                 using (FileStream fs = File.Create(sfd.FileName))
                 {
                     if (Path.GetExtension(sfd.FileName).ToLower() == ".txt")
                     {
                         doc.Save(fs, DataFormats.Text);
                     }
                     else if (Path.GetExtension(sfd.FileName).ToLower() == ".doc")
                     {
                         doc.Save(fs, DataFormats.Text);
                     }
                     else
                     {
                         doc.Save(fs, DataFormats.Xaml);
                     }
                 }
             }
         }
     }
 }
Exemple #27
0
        private void FileDrop(string[] files)
        {
            if (files == null || files.Length == 0)
            {
                return;
            }
            var validFiles = new List <string>();

            validFiles.AddRange(files.Where(f => Path.GetExtension(f) == ".ass"));
            if (validFiles.Count == 0)
            {
                return;
            }
            for (int i = 0; i < validFiles.Count(); ++i)
            {
                validFiles[i] = Path.GetFullPath(validFiles[i]);
            }

            this.AssFileList.ItemsSource = validFiles;
            string dir = Path.GetDirectoryName(validFiles[0]);

            this.FontFolder.Text   = dir + "\\fonts";
            this.OutputFolder.Text = dir + "\\output";

            this.FontFolder.Select(this.FontFolder.Text.Length - 1, 0);
            this.OutputFolder.Select(this.OutputFolder.Text.Length - 1, 0);
        }
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            saveCheck = true;
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "doc files (*.doc)|*.doc|Text Files (*.txt)|*.txt|XAML Files (*.xaml)|*.xaml|All files (*.*)|*.*";
            if (sfd.ShowDialog() == true)
            {
                TextRange doc = new TextRange(rich.Document.ContentStart, rich.Document.ContentEnd);
                using (FileStream fs = File.Create(sfd.FileName))
                {
                    if (Path.GetExtension(sfd.FileName).ToLower() == ".txt")
                    {
                        doc.Save(fs, DataFormats.Text);
                    }
                    else if (Path.GetExtension(sfd.FileName).ToLower() == ".doc")
                    {
                        doc.Save(fs, DataFormats.Text);
                    }
                    else
                    {
                        doc.Save(fs, DataFormats.Xaml);
                    }
                }
            }
        }
Exemple #29
0
        // With this method we can override how a file is exported in the PCK
        public override void _ExportFile(string path, string type, string[] features)
        {
            base._ExportFile(path, type, features);

            if (type != Internal.CSharpLanguageType)
            {
                return;
            }

            if (Path.GetExtension(path) != Internal.CSharpLanguageExtension)
            {
                throw new ArgumentException($"Resource of type {Internal.CSharpLanguageType} has an invalid file extension: {path}", nameof(path));
            }

            // TODO What if the source file is not part of the game's C# project

            bool includeScriptsContent = (bool)ProjectSettings.GetSetting("mono/export/include_scripts_content");

            if (!includeScriptsContent)
            {
                // We don't want to include the source code on exported games.

                // Sadly, Godot prints errors when adding an empty file (nothing goes wrong, it's just noise).
                // Because of this, we add a file which contains a line break.
                AddFile(path, System.Text.Encoding.UTF8.GetBytes("\n"), remap: false);

                // Tell the Godot exporter that we already took care of the file
                Skip();
            }
        }
    private void Save_OnClick(object sender, RoutedEventArgs e)
    {
        var vm  = (StatisticsViewModel)DataContext;
        var sfd = new SaveFileDialog
        {
            Filter           = "Scalable Vector Graphics (*.svg)|*.svg|Portable Network Graphics (*.png)|*.png",
            InitialDirectory = vm.WorkingDir
        };

        if (sfd.ShowDialog(this) != true)
        {
            return;
        }
        var filename = sfd.FileName;

        switch (Path.GetExtension(filename))
        {
        case ".svg":
            new SvgExporter
            {
                Width  = Settings.Instance.ExportWidth,
                Height = Settings.Instance.ExportHeight,
                Dpi    = Settings.Instance.ExportDPI
            }.Export(vm.PlotModel, File.Create(filename));
            break;

        case ".png":
            PngExporter.Export(vm.PlotModel, File.Create(filename), (int)Settings.Instance.ExportWidth, (int)Settings.Instance.ExportHeight, Settings.Instance.ExportDPI);
            break;

        default: throw new InvalidOperationException();
        }
    }