Ejemplo n.º 1
0
        private static void StoreAsAsciiFile(string text, int start, int end, string filePathNew)
        {
            using (MemoryStream bytes = new MemoryStream())
            {
                bool highByte = true;
                byte b        = 0;
                for (int i = start; i < end; i++)
                {
                    char c = text[i];
                    if (char.IsWhiteSpace(c))
                    {
                        continue;
                    }
                    if (highByte)
                    {
                        b = (byte)(16 * GetHexValue(c));
                    }
                    else
                    {
                        b |= GetHexValue(c);
                        bytes.WriteByte(b);
                    }

                    highByte = !highByte;
                }

                DirFiles.WriteAllBytes(filePathNew, bytes.ToArray());
            }
        }
        /// <summary>
        /// Copy file and take local path into consideration
        /// </summary>
        /// <param name="file"></param>
        /// <param name="target"></param>
        private void CopyEmbeddedFile(string file, string target)
        {
            string fileName = HoUtil.GetFilePath("Linked File", file);

            if (IsFileToProcess(fileName))
            {
                DirFiles.FileCopy(fileName, target);
            }
        }
Ejemplo n.º 3
0
        private const string WmfFile2Header = "02000900"; // Microsoft WMF format


        /// <summary>
        /// Save DOORS ole file in target format. If target format isn't supported the pure OLE file is stored.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="filePath"></param>
        /// <param name="ignoreNotSupportedFiles"></param>
        /// <returns></returns>
        public static string Save(string text, string filePath, bool ignoreNotSupportedFiles = true)
        {
            if (text == null)
            {
                MessageBox.Show("", @"No string to convert found for OLE convertion, break");
                return("");
            }

            if (filePath == null)
            {
                MessageBox.Show("", @"No filepath to convert OLE file to convertion, break");
                return("");
            }

            // Check if header is available
            // if not use the file extension .error
            int startCfb = StartCfbFormat(text);
            int startWmf = StartWmfFormat(text);

            // no supported file found
            if (startCfb < 0 && startWmf < 0)
            {
                if (!ignoreNotSupportedFiles)
                {
                    MessageBox.Show($@"File: '{filePath}'
CFB CfbHeader should be: '{CfbHeader}'
No CFB or WMF file found", @"File does not contain a CFB or WMF formatted file., break");
                }
                string newFilePath = $@"{filePath}.error";
                DirFiles.FileMove(filePath, newFilePath);
                return(newFilePath);
            }

            int start = startCfb > -1 ? startCfb : startWmf;
            int end   = text.IndexOf('}', start);

            if (end < 0)
            {
                end = text.Length;
            }

            if (startCfb > -1)
            {
                // CFB File
                return(StoreTargetFileFromCfb(text, filePath, ignoreNotSupportedFiles, start, end));
            }
            else
            {
                // WMF File
                return(StoreTargetFileFromWmf(text, filePath, start, end));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Store target file as *.wmf file
        /// </summary>
        /// <param name="text"></param>
        /// <param name="filePath"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private static string StoreTargetFileFromWmf(string text, string filePath, int start, int end)
        {
            string ext         = ".wmf";
            string filePathNew =
                Path.Combine(Path.GetDirectoryName(filePath), $"{Path.GetFileNameWithoutExtension(filePath)}{ext}");

            StoreAsAsciiFile(text, start, end, filePathNew);
            if (DirFiles.FileDelete(filePath))
            {
                return(filePathNew);
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 5
0
        internal void resizePNGsSaveAs(string dirSource, string dirDest,
                                       int percent)
        {
            if (!Directory.Exists(dirDest))
            {
                Directory.CreateDirectory(dirDest);
            }
            IEnumerable <FileInfo> fileListPNG =
                new DirFiles(dirSource).getPNGs;

            foreach (FileInfo item in fileListPNG)
            {
                img = Image.FromFile(item.FullName);
                saveAsNewPNG(resizeImage(new Size(img.Width * percent / 100,
                                                  img.Height * percent / 100)),
                             item.FullName.Replace(dirSource, dirDest));
            }
            Process ps = new Process();

            ps.StartInfo.FileName = dirDest;
            ps.Start();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Store the CFB file in target format
        /// </summary>
        /// <param name="text"></param>
        /// <param name="filePath"></param>
        /// <param name="ignoreNotSupportedFiles"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private static string StoreTargetFileFromCfb(string text, string filePath, bool ignoreNotSupportedFiles,
                                                     int start, int end)
        {
            // find object type of OLE
            Regex  rxObjectType = new Regex(@"objclass\s+([^}]*)}");
            Match  match        = rxObjectType.Match(text.Substring(0, 70));
            string typeText     = "";
            string ext          = "";

            if (match.Success)
            {
                typeText = match.Groups[1].Value;
            }

            // DOORS file types supported and tested
            string[] lTypes                  = { "AcroExch." }; //,"Excel.", "Word."};
            string[] lExtensions             = { ".pdf" };      //, "xlsx", "docx" };
            string[] lCompoundFileStreamName = { "CONTENTS" };
            int      j = 0;
            string   componentFileStreamName = "";

            foreach (var type in lTypes)
            {
                if (typeText.Contains(type))
                {
                    ext = lExtensions[j];
                    componentFileStreamName = lCompoundFileStreamName[j];
                    break;
                }

                j += 1;
            }

            if (ext == "")
            {
                string newFilePath = $@"{filePath}.notSupported";
                if (!ignoreNotSupportedFiles)
                {
                    MessageBox.Show($@"File: '{filePath}'
File type not supported: '{typeText}'

Supported ole types: '{String.Join(", ", lTypes)}'

Copied to:
{DirFiles.GetMessageFromFile(newFilePath)}

", @"Can't convert *.ole to file, not supported type!");
                }

                DirFiles.FileMove(filePath, newFilePath);
                return(newFilePath);
            }

            string filePathNew =
                Path.Combine(Path.GetDirectoryName(filePath), $"{Path.GetFileNameWithoutExtension(filePath)}{ext}");


            StoreAsAsciiFile(text, start, end, filePathNew);

            // By DOORS supported file type
            if (componentFileStreamName != "")
            {
                using (CompoundFile cf = new CompoundFile(filePathNew))
                {
                    CFStream foundStream = cf.RootStorage.GetStream("CONTENTS");
                    DirFiles.WriteAllBytes(filePathNew, foundStream.GetData().ToArray());
                }
            }

            if (DirFiles.FileDelete(filePath))
            {
                return(filePathNew);
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 7
0
 internal string getPicFullname(string whatsCharacter)
 {
     return(new FindFileThruLINQ().getfilefullnameIn古文字(whatsCharacter,
                                                        DirFiles.getPicDir(Form1.PicE) + "\\"));
 }
Ejemplo n.º 8
0
 internal void resizePNGsSaveAsZip(string dirSource, string dirDest,
                                   int percent)
 {
     resizePNGsSaveAs(dirSource, dirDest, percent);
     DirFiles.zipFolderFiles(dirDest);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Export all jobs of the current list number with the respectively defined settings. Only changed tagged values are exported/updated.
        /// </summary>
        /// <param name="listNumber"></param>
        /// <returns></returns>
        public bool RoundtripBySetting(int listNumber)
        {
            bool result = true;

            _level      = -1;
            _count      = 0;
            _countAll   = 0;
            _countPkg   = 0;
            _countItems = 0;
            foreach (FileImportSettingsItem item in _importSettings)
            {
                if (Convert.ToInt32(item.ListNo) == listNumber)
                {
                    // Copy input file to export file
                    if (!DirFiles.FileCopy(item.InputFile, item.ExportFile))
                    {
                        return(false);
                    }
                    _importModuleFile = item.ExportFile;
                    if (!System.IO.File.Exists(_importModuleFile))
                    {
                        MessageBox.Show($@"File: '{_importModuleFile}'", @"Import files doesn't exists, break");
                        return(false);
                    }
                    // check if there are columns to update
                    if (item.WriteAttrNameList.Count == 0)
                    {
                        var attributesToVisualize = String.Join(", ", item.WriteAttrNameList.ToArray());
                        MessageBox.Show($@"Roundtrip needs Attributes to write in Settings ('WriteAttrNameList' is empty):

File: '{_importModuleFile}'

Attributes to write ('{nameof(item.WriteAttrNameList)}'):
'{attributesToVisualize}'
", @"No Attributes to write in 'Setting.json' defined");
                        return(false);
                    }


                    // handle more than one package
                    // handle zip files like
                    foreach (var itemGuidList in item.PackageGuidList)
                    {
                        string guid = itemGuidList.Guid;
                        _pkg = _rep.GetPackageByGuid(guid);
                        if (_pkg == null)
                        {
                            MessageBox.Show(
                                $@"Package of export list {listNumber} with GUID='{guid}' not available.
{item.Description}
{item.Name}

    Check Import settings in Settings.Json.",
                                @"Package to import into isn't available, break!");
                            return(false);
                        }
                        switch (item.ImportType)
                        {
                        case FileImportSettingsItem.ImportTypes.DoorsReqIf:
                        case FileImportSettingsItem.ImportTypes.ReqIf:
                            var reqIfRoundtrip = new ReqIfs.ReqIfRoundtrip(_rep, _pkg, _importModuleFile, item);
                            result = result && reqIfRoundtrip.RoundtripForFile();
                            //await Task.Run(() =>
                            //    doorsReqIf.ImportForFile(eaObjectType, eaStereotype, eaStatusNew, eaStatusChanged));
                            break;
                        }
                    }
                }
            }

            return(true);
        }