예제 #1
0
        private void ProcessSourceFiles(string[] files)
        {
            try
            {
                Assembly        assembly = Assembly.GetExecutingAssembly();
                FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                string          version  = fvi.FileVersion;

                RevitFiles = new List <string>();
                var start = DateTime.Now;

                //seach subdirectories for revit files
                foreach (var s in files)
                {
                    if (Directory.Exists(s))
                    {
                        RevitFiles.AddRange(Directory.GetFiles(s, "*.rvt", SearchOption.AllDirectories).ToList());
                        RevitFiles.AddRange(Directory.GetFiles(s, "*.rfa", SearchOption.AllDirectories).ToList());
                    }

                    else if (File.Exists(s) &&
                             (s.ToLower().EndsWith(".rvt") || s.ToLower().EndsWith(".rfa")))
                    {
                        RevitFiles.Add(s);
                    }
                }
                //MessageBox.Show("Completed in " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds.");
                //user double clicked on the exe
                if (files.Length == 0)
                {
                    MessageBox.Show("No files Found!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                //no valid files found
                if (RevitFiles.Count == 0)
                {
                    MessageBox.Show("No Revit files found!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // SourceCollection.Clear();
                foreach (var f in RevitFiles)
                {
                    var rf = new RevitFile(f);
                    GetYearFromFileInfo(f, rf);
                    rf.RefreshName(GetSelectedAction());
                    SourceCollection.Add(rf);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private static void GetYearFromFileInfo(string pathToRevitFile, RevitFile rf)
        {
            try
            {
                var rawData = GetRawBasicFileInfo(
                    pathToRevitFile);

                var rawString = System.Text.Encoding.Unicode
                                .GetString(rawData);

                var fileInfoData = rawString.Split(
                    new string[] { "\0", "\r\n" },
                    StringSplitOptions.RemoveEmptyEntries);

                foreach (var info in fileInfoData)
                {
                    //Console.WriteLine(info);
                    if (info.Contains("Autodesk"))
                    {
                        Match match = FoundYear.Match(info);
                        if (match.Success)
                        {
                            rf.Version        = match.Value.Replace(" ", "");
                            rf.AdditionalInfo = info.Replace("Revit Build: ", "");
                            break;
                        }
                    }
                }

                //2019+ don't use the conventions above :(
                if (string.IsNullOrEmpty(rf.Version))
                {
                    foreach (var info in fileInfoData.Select((val, i) => new { i, val }))
                    {
                        Match yearMatch = FoundYear2019.Match(info.val);

                        if (yearMatch.Success)
                        {
                            rf.Version        = yearMatch.Groups[1].Value;
                            rf.AdditionalInfo = "Build: " + fileInfoData[info.i + 1];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private static string GetYearFromFileInfo(string pathToRevitFile, RevitFile rf)
        {
            string version = "????";

            try
            {
                var rawData = GetRawBasicFileInfo(
                    pathToRevitFile);

                var rawString = System.Text.Encoding.Unicode
                                .GetString(rawData);

                var fileInfoData = rawString.Split(
                    new string[] { "\0", "\r\n" },
                    StringSplitOptions.RemoveEmptyEntries);

                foreach (var info in fileInfoData)
                {
                    //Console.WriteLine(info);
                    if (info.Contains("Autodesk"))
                    {
                        Match match = FoundYear.Match(info);
                        if (match.Success)
                        {
                            rf.Version        = match.Value.Replace(" ", "");
                            rf.AdditionalInfo = info.Replace("Revit Build: ", "");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(version);
        }