예제 #1
0
        public void TestEmptyGroupImportGroupFileSameDir()
        {
            /*
             * dir
             *  group1.stg		that imports group2.stg in same dir with just filename
             *  group2.stg		has c()
             */
            string dir       = tmpdir;
            string groupFile =
                "import \"group2.stg\"\n";

            writeFile(dir, "group1.stg", groupFile);

            groupFile =
                "c() ::= \"g2 c\"\n";
            writeFile(dir, "group2.stg", groupFile);

            TemplateGroup group1   = new TemplateGroupFile(Path.Combine(dir, "group1.stg"));
            Template      st       = group1.GetInstanceOf("c"); // should see c()
            string        expected = "g2 c";
            string        result   = st?.Render();

            Assert.AreEqual(expected, result);
        }
예제 #2
0
        public static void Create(TuxConfig cfg, params IEnumerable <IContent>[] contents)
        {
            var          destination = new File(cfg.AppTemp);
            var          arch        = Architecture.X86_64;
            var          host        = Environment.MachineName;
            const string license     = "Proprietary";
            const string release     = "unstable";
            const string group       = "gnome";
            var          desc        = FormatDesc(cfg.Description).Split('\n');
            var          summary     = desc.First();
            var          description = string.Join(string.Empty, desc.Skip(1));
            var          include     = new Contents();
            var          packer      = new RpmContents(include);
            var          allContents = contents.SelectMany(c => c).ToArray();

            Array.ForEach(allContents, packer.Add);
            var builder = new Builder();

            builder.setPackage(cfg.PkgName, cfg.Version, release);
            builder.setType(RpmType.BINARY);
            builder.setPlatform(arch, Os.LINUX);
            builder.setSummary(summary);
            builder.setDescription(description);
            builder.setBuildHost(host);
            builder.setLicense(license);
            builder.setGroup(group);
            builder.setPackager(cfg.Maintainer.Split('<').First().Trim());
            builder.setVendor(cfg.Maintainer);
            builder.setUrl(cfg.Homepage);
            builder.setProvides(cfg.PkgName);
            builder.setFiles(include);
            var tmpFileName = Path.Combine(cfg.AppTemp, builder.build(destination));
            var fileName    = $"{cfg.PackageFile}.rpm";

            NetFile.Copy(tmpFileName, fileName, true);
        }
예제 #3
0
        public void TestNestedWithIndentAndTrackStartOfExpr()
        {
            string templates =
                "top(d) ::= <<  <d>!>>" + newline +
                "duh(chars) ::= <<" + newline +
                "x: <chars; anchor, wrap=\"\\n\">" + newline +
                ">>" + newline;

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));

            Template top = group.GetInstanceOf("top");
            Template duh = group.GetInstanceOf("duh");

            duh.Add("chars", new string[] { "a", "b", "c", "d", "e" });
            top.Add("d", duh);
            //
            string expecting =
                "  x: ab" + Environment.NewLine +
                "     cd" + Environment.NewLine +
                "     e!";

            Assert.AreEqual(expecting, top.Render(7));
        }
예제 #4
0
        public void TestNestedIndentedExpr()
        {
            string templates =
                "top(d) ::= <<  <d>!>>" + newline +
                "duh(chars) ::= <<" + newline +
                "  <chars; wrap=\"\\n\">" + newline +
                ">>" + newline;

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));

            Template top = group.GetInstanceOf("top");
            Template duh = group.GetInstanceOf("duh");

            duh.Add("chars", new string[] { "a", "b", "c", "d", "e" });
            top.Add("d", duh);
            string expecting =
                "    ab" + Environment.NewLine +
                "    cd" + Environment.NewLine +
                "    e!";

            // width=4 spaces + 2 char.
            Assert.AreEqual(expecting, top.Render(6));
        }
예제 #5
0
        public void TestImportTemplateInGroupFileFromGroupFile()
        {
            string dir       = tmpdir;
            string groupFile =
                "a() ::= \"g1 a\"\n" +
                "b() ::= \"<c()>\"\n";

            writeFile(dir, Path.Combine("x", "group.stg"), groupFile);

            groupFile =
                "b() ::= \"g2 b\"\n" +
                "c() ::= \"g2 c\"\n";
            writeFile(dir, Path.Combine("y", "group.stg"), groupFile);

            TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "x", "group.stg"));
            TemplateGroup group2 = new TemplateGroupFile(Path.Combine(dir, "y", "group.stg"));

            group1.ImportTemplates(group2);
            Template st       = group1.GetInstanceOf("b");
            string   expected = "g2 c";
            string   result   = st?.Render();

            Assert.AreEqual(expected, result);
        }
예제 #6
0
        public void Execute(IConfiguration configuration, StepType currentStep)
        {
            FilePath apkPath = configuration.GetSimple <string>(AndroidConstants.GENERATED_ANDROID_PACKAGE_PATH_KEY);

            string buildPath     = configuration.GetBuildPath().FullPath;
            string artifactsPath = configuration.GetArtifactsPath().FullPath;

            string apkName = apkPath.GetFilename().ToString();
            string apkNameWithoutExtension = apkPath.GetFilenameWithoutExtension().ToString();
            string apkExtension            = apkPath.GetExtension();

            string sourceApkPath = Path.Combine(buildPath, apkName);

            configuration.Context.CakeContext.CopyFile(apkPath, sourceApkPath);

            string signedApkPath = Path.Combine(buildPath, $"{apkNameWithoutExtension}-Signed{apkExtension}");

            JarsignerCommand jarSignerCommand = new JarsignerCommand(configuration.Context.CakeContext);

            Sign(jarSignerCommand, configuration, sourceApkPath, signedApkPath);
            jarSignerCommand.VerifyApk(signedApkPath);

            string          alignedApkPath  = Path.Combine(buildPath, $"{apkNameWithoutExtension}-Aligned{apkExtension}");
            ZipAlignCommand zipAlignCommand = new ZipAlignCommand(configuration.Context.CakeContext);

            zipAlignCommand.Align(signedApkPath, alignedApkPath);

            string resultApkPath = Path.Combine(artifactsPath, apkName);

            if (configuration.Context.CakeContext.FileExists(resultApkPath))
            {
                configuration.Context.CakeContext.DeleteFile(resultApkPath);
            }

            configuration.Context.CakeContext.CopyFile(alignedApkPath, resultApkPath);
        }
예제 #7
0
 public string GetNewA11yTestFilePath()
 {
     return(Path.Combine(_outputDirectory
                         , GetNewFileName()
                         + ".a11ytest"));
 }
예제 #8
0
        public static byte[] CreateLabels(IEnumerable <Expansion> selectedExpansions, bool includeSpecialSetupCards)
        {
            var allHeroes        = DataAccess.GetHeroCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(heroCardSet => heroCardSet.Heroes);
            var allMasterminds   = DataAccess.GetMastermindCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(mastermindCardSet => mastermindCardSet.Masterminds);
            var allVillains      = DataAccess.GetVillainCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(villainCardSet => villainCardSet.Villains);
            var allHenchmen      = DataAccess.GetHenchmenCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(henchmenCardSet => henchmenCardSet.Henchmen);
            var allStartingCards = DataAccess.GetStartingCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(startingCardSet => startingCardSet.StartingCards);
            var allSetupCards    = DataAccess.GetSetupCardSets()
                                   .Where(set => selectedExpansions.Contains(set.Expansion))
                                   .SelectMany(setupCardSet => setupCardSet.SetupCards)
                                   .Where(setupCard => includeSpecialSetupCards || !setupCard.IsSpecialCard);
            var allVillainSetupCards = DataAccess.GetVillainSetupCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(setupCardSet => setupCardSet.VillainSetupCards);

            var mastermindBaseColor       = new DeviceRgb(255, 61, 83);
            var villainBaseColor          = new DeviceRgb(255, 102, 119);
            var henchmenBaseColor         = new DeviceRgb(255, 173, 182);
            var startingCardBaseColor     = new DeviceRgb(200, 200, 200);
            var setupCardBaseColor        = new DeviceRgb(35, 255, 39);
            var villainSetupCardBaseColor = new DeviceRgb(255, 73, 197);

            var fontPath        = Path.Combine(CurrentPath, "Fonts", "KOMIKAX.TTF");
            var font            = PdfFontFactory.CreateFont(fontPath, true);
            var drawHeroActions = allHeroes.Select(hero => new Action <PdfCanvas, Rectangle>(
                                                       (canvas, rectangle) =>
            {
                var topCursor    = new Cursor();
                var bottomCursor = new Cursor();
                const float startOfLabelOffset = 4f;
                topCursor.AdvanceCursor(rectangle.GetTop() - startOfLabelOffset);
                bottomCursor.AdvanceCursor(rectangle.GetBottom() + startOfLabelOffset);
                TextSharpHelpers.DrawRoundedRectangle(canvas, rectangle, new DeviceRgb(168, 255, 247));

                DrawFactionsAndTypes(hero, rectangle, canvas, topCursor, bottomCursor);

                DrawCardText(rectangle, topCursor, bottomCursor, canvas, hero.Name, font);
                DrawSetText(rectangle, topCursor, bottomCursor, canvas, hero.Expansion.GetExpansionName(), font);
            }
                                                       )).ToList();
            var drawMastermindActions = allMasterminds.Select(mastermind =>
                                                              CreateActionToDrawNameAndSet(
                                                                  mastermind.Name,
                                                                  mastermind.Expansion.GetExpansionName(),
                                                                  font,
                                                                  mastermindBaseColor
                                                                  ));
            var drawVillainActions = allVillains.Select(villain =>
                                                        CreateActionToDrawNameAndSet(
                                                            villain.Name,
                                                            villain.Expansion.GetExpansionName(),
                                                            font,
                                                            villainBaseColor
                                                            ));
            var drawHenchmenActions = allHenchmen.Select(henchmen =>
                                                         CreateActionToDrawNameAndSet(
                                                             henchmen.Name,
                                                             henchmen.Expansion.GetExpansionName(),
                                                             font,
                                                             henchmenBaseColor
                                                             ));
            var drawStartingCardsActions = allStartingCards.Select(startingCard =>
                                                                   CreateActionToDrawNameAndSet(
                                                                       startingCard.Name,
                                                                       startingCard.Expansion.GetExpansionName(),
                                                                       font,
                                                                       startingCardBaseColor
                                                                       ));
            var drawSetupCardsActions = allSetupCards.Select(setupCard =>
                                                             CreateActionToDrawNameAndSet(
                                                                 setupCard.Name,
                                                                 setupCard.Expansion.GetExpansionName(),
                                                                 font,
                                                                 setupCardBaseColor
                                                                 ));
            var drawVillainSetupCardsActions = allVillainSetupCards.Select(villainSetupCard =>
                                                                           CreateActionToDrawNameAndSet(
                                                                               villainSetupCard.Name,
                                                                               villainSetupCard.Expansion.GetExpansionName(),
                                                                               font,
                                                                               villainSetupCardBaseColor
                                                                               ));


            var allActions = drawHeroActions
                             .Concat(drawMastermindActions)
                             .Concat(drawVillainActions)
                             .Concat(drawHenchmenActions)
                             .Concat(drawStartingCardsActions)
                             .Concat(drawSetupCardsActions)
                             .Concat(drawVillainSetupCardsActions);

            var drawActionRectangleQueue = new Queue <Action <PdfCanvas, Rectangle> >(allActions);

            return(PdfGenerator.DrawRectangles(drawActionRectangleQueue, ColorConstants.WHITE));
        }
예제 #9
0
        public void RunWithArguments(Document doc, NameValueMap map)
        {
            LogTrace("Processing " + doc.FullFileName);

            try
            {
                if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
                {
                    LogTrace("We don't yet process parts in this example");
                    using (new HeartBeat())
                    {
                        // TODO: handle the Inventor part here
                    }
                }
                else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) // Assembly.
                {
                    using (new HeartBeat())
                    {
                        LogTrace("We have an assembly file!");

                        // JSON File with params is the first thing passed in
                        string paramFile = (string)map.Value[$"_1"];
                        LogTrace($"Reading param file {paramFile}");
                        string json = File.ReadAllText(paramFile);

                        // Loop through params and set each one
                        Dictionary <string, string> parameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
                        foreach (KeyValuePair <string, string> entry in parameters)
                        {
                            var paramName  = entry.Key;
                            var paramValue = entry.Value;
                            LogTrace($" params: {paramName}, {paramValue}");
                            ChangeParam((AssemblyDocument)doc, paramName, paramValue);
                        }
                    }

                    // Get the full name to use in zipping up the output assembly
                    LogTrace($"Getting full file name of assembly");
                    var docDir   = Path.GetDirectoryName(doc.FullFileName);
                    var pathName = doc.FullFileName;
                    doc.Update2(true);;

                    LogTrace($"Saving updated assembly");
                    doc.Save2(true);
                    doc.Close(true);

                    // Zip up the output assembly
                    //
                    // assembly lives in own folder under WorkingDir. Get the WorkingDir
                    var workingDir = Path.GetDirectoryName(docDir);
                    var fileName   = Path.Combine(workingDir, "result.zip"); // the name must be in sync with OutputIam localName in Activity
                    LogTrace($"Zipping up {fileName}");

                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    // start HeartBeat around ZipFile, it could be a long operation
                    using (new HeartBeat())
                    {
                        ZipFile.CreateFromDirectory(Path.GetDirectoryName(pathName), fileName, CompressionLevel.Fastest, false);
                    }

                    LogTrace($"Saved as {fileName}");
                }
            }
            catch (Exception e)
            {
                LogError("Processing failed. " + e.ToString());
            }
        }
예제 #10
0
 public static void writeFile(string dir, string fileName, string content)
 {
     File.WriteAllText(Path.Combine(dir, fileName), content);
 }
예제 #11
0
 public ch.cyberduck.core.Local find()
 {
     return
         (LocalFactory.get(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                        PreferencesFactory.get().getProperty("application.datafolder.name"))));
 }
        public ReadOnlyCollection <string> GetSourcePaths(string stratum)
        {
            if (stratum != "Java")
            {
                return(new ReadOnlyCollection <string>(new string[0]));
            }

            if (_taggedTypeId.TypeTag == TypeTag.Class || _taggedTypeId.TypeTag == TypeTag.Interface)
            {
                string signature      = GetSignature().Substring(1);
                string relativeFolder = null;
                if (signature.IndexOf('/') >= 0)
                {
                    relativeFolder = signature.Substring(0, signature.LastIndexOf('/')).Replace('/', Path.DirectorySeparatorChar);
                }

                List <string> paths = new List <string>(GetSourceNames(stratum).Select(i => string.IsNullOrEmpty(relativeFolder) ? i : Path.Combine(relativeFolder, i)));
                for (int i = paths.Count - 1; i >= 0; i--)
                {
                    string        path           = paths[i];
                    List <string> qualifiedPaths = VirtualMachine.SourcePaths.Select(j => Path.Combine(j, path)).Where(File.Exists).ToList();
                    if (qualifiedPaths.Count > 0)
                    {
                        paths.RemoveAt(i);
                        paths.InsertRange(i, qualifiedPaths);
                    }
                }

                return(paths.AsReadOnly());
            }
            else
            {
                // TODO: get actual source paths
                return(GetSourceNames(stratum));
            }
        }
예제 #13
0
 public DirRef Dir(string dirName)
 {
     return(From(IOPath.Combine(Path, dirName).Replace("\\", "/")));
 }
예제 #14
0
 public FileRef File(string fileName)
 {
     return(FileRef.From(IOPath.Combine(Path, fileName).Replace("\\", "/")));
 }
예제 #15
0
        private void TakeFromVideoClicked(object sender, RoutedEventArgs e)
        {
            TimeSpan start       = TimeSpan.FromSeconds(startTime.Value.Value);
            TimeSpan duration    = TimeSpan.FromSeconds(lengthTime.Value.Value);
            string   fileName    = textBoxId.Text + ".wav";
            string   cmdLineArgs = string.Format("-ss {0} -t {1} -i \"{2}\" \"{3}\"", start.TotalSeconds, duration.TotalSeconds, videoFileName, Path.Combine(directory, fileName));
            Process  process     = Process.Start("ffmpeg.exe", cmdLineArgs);

            process.WaitForExit();
            textBoxSoundFileName.Text = fileName;
        }
예제 #16
0
파일: Game.cs 프로젝트: MaciejSzpakowski/mu
 private void LoadGlobalAssets()
 {
     Globals.Font = new BitmapFont(IOPath.Combine(Path.Font, "font.png"),
                                   IOPath.Combine(Path.Font, "font.fnt"), FlatRedBallServices.GlobalContentManager);
 }
예제 #17
0
        protected override string GetUserUserDataRootFolder()
        {
            string userDataDirectory = Path.Combine(TestDirectory, @"core\userdata");

            return(userDataDirectory);
        }
예제 #18
0
 public static string Combine(string s, string d) => OgPath.Combine(s, d);
        public void RunWithArguments(Document doc, NameValueMap map)
        {
            // write diagnostics data
            LogInputData(doc, map);

            var pathName = doc.FullFileName;

            LogTrace("Processing " + pathName);

            string[] outputFileName = { "", "ResultSmall", "ResultLarge" };

            try
            {
                var documentType = doc.DocumentType;
                var iRuns        = 1;
                if (documentType == DocumentTypeEnum.kPartDocumentObject)
                {
                    iRuns = 2;
                }
                for (int iRun = 1; iRun <= iRuns; iRun++)
                {
                    // load processing parameters
                    string paramsJson = GetParametersToChange(map, iRun);

                    // update parameters in the doc
                    // start HeartBeat around ChangeParameters, it could be a long operation
                    using (new HeartBeat())
                    {
                        ChangeParameters(doc, paramsJson);
                    }

                    var docDir = Path.GetDirectoryName(doc.FullFileName);

                    if (documentType == DocumentTypeEnum.kPartDocumentObject)
                    {
                        PartDocument part           = (PartDocument)doc;
                        double       mass           = part.ComponentDefinition.MassProperties.Mass;
                        string       imageParamName = "ImageLight";

                        // check the mass of the document and download proper image
                        if (mass > 300.0)
                        {
                            imageParamName = "ImageHeavy";
                        }

                        // get Image from the OnDemand parameter
                        OnDemand.HttpOperation(imageParamName, "", null, "", $"file://{outputFileName[iRun]}.png");
                    }

                    // generate outputs
                    if (documentType == DocumentTypeEnum.kPartDocumentObject)
                    {
                        var fileName = Path.Combine(docDir, $"{outputFileName[iRun]}.ipt"); // the name must be in sync with OutputIpt localName in Activity
                        LogTrace("Saving " + fileName);
                        // start HeartBeat around Save, it could be a long operation
                        using (new HeartBeat())
                        {
                            doc.SaveAs(fileName, false);
                        }
                        LogTrace("Saved as " + fileName);

                        // save an image
                        SaveImageFromPart(Path.Combine(docDir, $"{outputFileName[iRun]}.bmp"), doc as PartDocument);
                    }
                    else // Assembly. That's already validated in ChangeParameters
                    {
                        //Generate drawing document with assembly
                        var idwPath = Path.ChangeExtension(Path.Combine(docDir, doc.DisplayName), "idw");
                        LogTrace($"Generate drawing document");
                        SaveAsIDW(idwPath, doc);

                        // cannot ZIP opened assembly, so close it
                        // start HeartBeat around Save, it could be a long operation
                        using (new HeartBeat())
                        {
                            doc.Save2(true);
                        }
                        doc.Close(true);

                        LogTrace("Zipping up updated Assembly.");

                        // assembly lives in own folder under WorkingDir. Get the WorkingDir
                        var workingDir = Path.GetDirectoryName(docDir);
                        var fileName   = Path.Combine(workingDir, "Result.zip"); // the name must be in sync with OutputIam localName in Activity

                        if (File.Exists(fileName))
                        {
                            File.Delete(fileName);
                        }

                        // start HeartBeat around ZipFile, it could be a long operation
                        using (new HeartBeat())
                        {
                            ZipFile.CreateFromDirectory(Path.GetDirectoryName(pathName), fileName, CompressionLevel.Fastest, false);
                        }

                        LogTrace($"Saved as {fileName}");
                    }
                }
            }
            catch (Exception e)
            {
                LogError("Processing failed. " + e.ToString());
            }
        }
예제 #20
0
 private static string GetFgdbDatasetPath([NotNull] IObjectClass objectClass)
 {
     return(Path.Combine(DatasetUtils.GetWorkspace(objectClass).PathName,
                         DatasetUtils.GetName(objectClass)));
 }
예제 #21
0
        public ButterLibSettingsContainer(ILogger <ButterLibSettingsContainer> logger)
        {
            RootFolder = Path.Combine(FSIOHelper.GetConfigPath(), "ModSettings");

            RegisterSettings(new ButterLibSettings());
        }
예제 #22
0
        void Initialize()
        {
            var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Stocks.db");

            _db = new Database(dbPath);
        }
예제 #23
0
 public static string Combine(string path1, string path2)
 {
     return(ReplaceSeparators(SystemPath.Combine(path1, path2)));
 }
예제 #24
0
 public void CreatePdfFile(CompetitionResult competitionResult)
 {
     CreatePdfFile(competitionResult.data, Path.Combine(relativePath, $"{FileName}.pdf"));
 }
예제 #25
0
        private static void DrawSingleCardType(HeroCardType heroCardType, Rectangle rectangle, PdfCanvas canvas, Cursor bottomCursor)
        {
            var imagePath = Path.Combine(CurrentPath, "Legendary", "images", "Types", $"{heroCardType}.png");

            DrawCardType(rectangle, canvas, bottomCursor, imagePath);
        }
예제 #26
0
 private static void DrawBackground(PdfCanvas canvas, Rectangle rectangle, string dividerType)
 {
     DrawImage(rectangle, canvas, Path.Combine(CurrentPath, "AeonsEnd", $"{dividerType}.png"), centerHorizontally: true, centerVertically: true);
 }
예제 #27
0
 private void MusicPlayerWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     FilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MusicPlayer", "TestFiles", "a1.mp3");
     //FilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MusicPlayer", "TestFiles", "喜洋洋.wav");
 }
        private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper()
        {
            AntlrClassGenerationTaskInternal wrapper = new AntlrClassGenerationTaskInternal();

            IList <string> sourceCodeFiles = null;

            if (this.SourceCodeFiles != null)
            {
                sourceCodeFiles = new List <string>(SourceCodeFiles.Length);
                foreach (ITaskItem taskItem in SourceCodeFiles)
                {
                    sourceCodeFiles.Add(taskItem.ItemSpec);
                }
            }

            if (this.TokensFiles != null && this.TokensFiles.Length > 0)
            {
                Directory.CreateDirectory(OutputPath);

                HashSet <string> copied = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                foreach (ITaskItem taskItem in TokensFiles)
                {
                    string fileName = taskItem.ItemSpec;
                    if (!File.Exists(fileName))
                    {
                        Log.LogError("The tokens file '{0}' does not exist.", fileName);
                        continue;
                    }

                    string vocabName = Path.GetFileNameWithoutExtension(fileName);
                    if (!copied.Add(vocabName))
                    {
                        Log.LogWarning("The tokens file '{0}' conflicts with another tokens file in the same project.", fileName);
                        continue;
                    }

                    string target = Path.Combine(OutputPath, Path.GetFileName(fileName));
                    if (!Path.GetExtension(target).Equals(".tokens", StringComparison.OrdinalIgnoreCase))
                    {
                        Log.LogError("The destination for the tokens file '{0}' did not have the correct extension '.tokens'.", target);
                        continue;
                    }

                    File.Copy(fileName, target, true);
                    File.SetAttributes(target, File.GetAttributes(target) & ~FileAttributes.ReadOnly);
                }
            }

            wrapper.ToolPath                 = ToolPath;
            wrapper.SourceCodeFiles          = sourceCodeFiles;
            wrapper.TargetLanguage           = TargetLanguage;
            wrapper.TargetFrameworkVersion   = TargetFrameworkVersion;
            wrapper.OutputPath               = OutputPath;
            wrapper.Encoding                 = Encoding;
            wrapper.LanguageSourceExtensions = LanguageSourceExtensions;
            wrapper.TargetNamespace          = TargetNamespace;
            wrapper.GenerateListener         = GenerateListener;
            wrapper.GenerateVisitor          = GenerateVisitor;
            wrapper.ForceAtn                 = ForceAtn;
            wrapper.AbstractGrammar          = AbstractGrammar;
            wrapper.JavaVendor               = JavaVendor;
            wrapper.JavaInstallation         = JavaInstallation;
            wrapper.JavaExecutable           = JavaExecutable;
            wrapper.UseCSharpGenerator       = UseCSharpGenerator;
            return(wrapper);
        }
예제 #29
0
 private void ListBoxItem_ViewWordDocumentType_OnSelected(object p_sender, RoutedEventArgs p_e)
 {
     Process.Start("word.exe",
                   Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                @"Components\LisaResume.docx"));
 }
예제 #30
0
        /// <summary>
        /// Creates a DataDir for a generic path for the provided application name.
        /// </summary>
        public static DataDir Create(string applicationName, string companyName = null, DataDirType type = DataDirType.RoamingUser)
        {
            if (string.IsNullOrEmpty(applicationName))
            {
                throw new ArgumentException(nameof(applicationName), "Application name cannot be null or empty.");
            }

            bool   isUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
            string parentDirectory;

            string homeDirectory = Environment.GetEnvironmentVariable("HOME");

            if (!isUnix && string.IsNullOrEmpty(homeDirectory))
            {
                homeDirectory = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
            }
            if (string.IsNullOrEmpty(homeDirectory))
            {
                homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            }

            switch (type)
            {
            case DataDirType.RoamingUser:
                parentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                if (string.IsNullOrEmpty(parentDirectory))
                {
                    parentDirectory = PathType.Combine(homeDirectory, ".config");
                }
                break;

            case DataDirType.LocalUser:
                parentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                if (string.IsNullOrEmpty(parentDirectory))
                {
                    parentDirectory = PathType.Combine(homeDirectory, ".local", "share");
                }
                break;

            case DataDirType.SystemWide:
                parentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                if (string.IsNullOrEmpty(parentDirectory))
                {
                    parentDirectory = isUnix ? "/usr/share" : PathType.Combine(homeDirectory, "\\ProgramData");
                }
                break;

            case DataDirType.Temporary:
                parentDirectory = PathType.GetTempPath();
                break;

            case DataDirType.SavedGameData:
                parentDirectory = Native.GetKnownFolderPath(
                    new Guid("4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4"),
                    isUnix ?
                    PathType.Combine(homeDirectory, ".local/share/games") :
                    PathType.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games")
                    );
                break;

            default:
                throw new InvalidOperationException("Unsupported data directory type: " + type.ToString());
            }

            var  invalids    = PathType.GetInvalidFileNameChars();
            var  dataDirName = new StringBuilder();
            bool isValid;

            // company name subdirectories are common on windows but not on unix
            // therefore, only add the company name if not on unix
            if (!string.IsNullOrEmpty(companyName) && !isUnix)
            {
                foreach (char c in companyName)
                {
                    isValid = true;
                    for (int i = 0; i < invalids.Length; i++)
                    {
                        if (invalids[i] == c)
                        {
                            isValid = false;
                            break;
                        }
                    }
                    dataDirName.Append(isValid ? c : '_');
                }
                dataDirName.Append(PathType.DirectorySeparatorChar);
            }

            foreach (char c in applicationName)
            {
                isValid = true;
                for (int i = 0; i < invalids.Length; i++)
                {
                    if (invalids[i] == c)
                    {
                        isValid = false;
                        break;
                    }
                }
                dataDirName.Append(isValid ? c : '_');
            }

            // check for reserved file names, and do something about it if necessary
            foreach (string part in dataDirName.ToString().Split(PathType.DirectorySeparatorChar))
            {
                isValid = true;

                if (part == "." || part == "..")
                {
                    isValid = false;
                }

                // thanks dos. thos.
                if (!isUnix)
                {
                    if (part.Length == 3)
                    {
                        switch (part.ToUpperInvariant())
                        {
                        case "CON":
                        case "PRN":
                        case "AUX":
                        case "NUL":
                            isValid = false;
                            break;
                        }
                    }
                    else if (part.Length == 4)
                    {
                        switch (part.Substring(0, 3).ToUpperInvariant())
                        {
                        case "COM":
                        case "LPT":
                            isValid = false;
                            break;
                        }
                    }
                }

                if (isValid)
                {
                    parentDirectory = PathType.Combine(parentDirectory, part);
                }
                else
                {
                    parentDirectory = PathType.Combine(parentDirectory, part + "_");
                }
            }

            var dir = new DataDir(parentDirectory);

            dir.CreateIfNotExists();
            return(dir);
        }