Ejemplo n.º 1
0
        private void PrepareTestEnvironment()
        {
            var homeDir = RootDir.CreateDirectory(".home");
            var xdgDir  = RootDir.CreateDirectory(".xdg");

            EnvironmentVariables.Add("XDG_CONFIG_HOME", xdgDir.Path);
            EnvironmentVariables.Add("HOME", homeDir.Path);

            if (PathUtils.IsUnixLikePlatform)
            {
                EnvironmentVariables.Add("MICROSOFT_SOURCELINK_TEST_ENVIRONMENT_ETC_DIR", homeDir.Path);

                xdgDir.CreateDirectory("git").CreateFile("config").WriteAllText(@"[remote ""origin2""]url = http://github.com/test-org/test-repo2");
            }
            else
            {
                var gitInstallDir = RootDir.CreateDirectory(".gitinstall");
                var gitExeDir     = gitInstallDir.CreateDirectory("bin");
                gitExeDir.CreateFile("git.exe");
                var etcDir = gitInstallDir.CreateDirectory("mingw64").CreateDirectory("etc");

                etcDir.CreateFile("gitconfig").WriteAllText(@"[remote ""origin2""]url = http://github.com/test-org/test-repo2");

                var programDataDir = RootDir.CreateDirectory(".programdata");

                EnvironmentVariables.Add("USERPROFILE", homeDir.Path);
                EnvironmentVariables.Add("PATH", gitExeDir.Path);
                EnvironmentVariables.Add("PROGRAMDATA", programDataDir.Path);
            }
        }
Ejemplo n.º 2
0
        public void TestMethod_RootDir()
        {
            Directory.CreateDirectory("testDir/root/");
            File.Create("testDir/file1.txt").Close();
            File.Create("testDir/file2.txt").Close();
            File.Create("testDir/root/file1.txt").Close();
            File.Create("testDir/root/file2.txt").Close();
            File.Create("testDir/root/file3.txt").Close();
            RootDir rootDir = new RootDir();

            rootDir.InitWithPath("testDir/");

            string fp1 = rootDir.GetFullPath("dir1/dir2/dir3/file.txt");

            Assert.IsTrue(fp1.Contains("testDir\\dir1\\dir2"));
            fp1 = rootDir.GetFullPath("dir1\\dir2\\dir3\\file.txt");
            Assert.IsTrue(fp1.Contains("testDir\\dir1\\dir2"));

            rootDir.CalcMD5();

            foreach (var kvp in rootDir.dict)
            {
                //空文件的md5值是固定的这个值
                Assert.IsTrue(kvp.Value.MD5 == "d41d8cd98f00b204e9800998ecf8427e");
            }
        }
Ejemplo n.º 3
0
 public XisoFileEntry GetEntry(string path)
 {
     if (path.EndsWith(Slash))
     {
         path = path.Substring(0, path.Length - 1);
     }
     return(RootDir.Find(path));
 }
Ejemplo n.º 4
0
        public void MutlipleProjects()
        {
            var projectName2     = "Project2";
            var projectFileName2 = projectName2 + ".csproj";

            var project2 = RootDir.CreateDirectory(projectName2).CreateFile(projectFileName2).WriteAllText(@"
<Project Sdk='Microsoft.NET.Sdk'>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>
");

            using var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(
                      RootDir.Path,
                      new[] { Path.Combine(ProjectName, ProjectFileName), Path.Combine(projectName2, projectFileName2) },
                      "http://github.com/test-org/test-repo1");

            repo.Network.Remotes.Add("origin2", "http://github.com/test-org/test-repo2");

            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: $@"
<ItemGroup>
  <ProjectReference Include='{project2.Path}'/>
</ItemGroup>
<PropertyGroup>
  <GitRepositoryRemoteName>origin2</GitRepositoryRemoteName>
</PropertyGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                SourceRoot,
                $"https://raw.githubusercontent.com/test-org/test-repo2/{commitSha}/*",
                s_relativeSourceLinkJsonPath,
                $"http://github.com/test-org/test-repo2",
            },
                // the second project should reuse the repository info cached by the first project:
                buildVerbosity: "detailed",
                expectedBuildOutputFilter: line => line.Contains("SourceLink: Reusing cached git repository information."));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads all the pending tasks.
        /// </summary>
        public void Load()
        {
            if (!loaded)
            {
                foreach (var fi in RootDir.GetFiles())
                {
                    LoadTask(fi.FullName);
                }

                loaded = true;
            }
        }
        public void Cleanup()
        {
            CleanupInternal();

            if (DownloadService.GetTransferStatus(Token.TransferId) != TransferStatus.UnknownTransfer)
            {
                DownloadService.CancelTransfer(Token.TransferId, AbortReason.Undefined);
            }

            SystemTime.Reset();
            RootDir.Delete(true);
        }
Ejemplo n.º 7
0
 GitFolder(Repository r, ProtoGitFolder data)
     : base(data, r, data.FullPhysicalPath, data.FolderPath)
 {
     _headFolder           = new HeadFolder(this);
     _branchesFolder       = new BranchesFolder(this, "branches", isRemote: false);
     _remoteBranchesFolder = new RemotesFolder(this);
     _thisDir         = new RootDir(this, SubPath.LastPart);
     ServiceContainer = new SimpleServiceContainer(FileSystem.ServiceContainer);
     ServiceContainer.Add(this);
     PluginManager = new GitPluginManager(data.PluginRegistry, ServiceContainer, data.CommandRegister, data.World.DevelopBranchName);
     data.CommandRegister.Register(this);
 }
Ejemplo n.º 8
0
        public void Rebuild(string targetPath, bool skipSystemUpdate)
        {
            if (skipSystemUpdate)
            {
                RootDir.Remove("\\$SystemUpdate");
            }

            var filename = Path.GetFileName(_path).Replace(".iso", "_rebuilt.iso");
            var path     = Path.Combine(targetPath, filename);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            using (var stream = File.OpenWrite(path))
            {
                using (var writer = new BinaryWriter(stream))
                {
                    var  magic         = Encoding.ASCII.GetBytes(VolumeDescriptor.Magic);
                    uint rootDirSector = 0x24;
                    uint rootDirSize;
                    var  lastDataSector = WriteDirectoryContents(writer, Slash, 0x24, out rootDirSize);
                    var  length         = _gamePartition.SectorToOffset(lastDataSector);
                    writer.BaseStream.SetLength(length);

                    writer.Seek(0, SeekOrigin.Begin);
                    writer.Write((uint)0x1a465358);
                    writer.Write((uint)0x400);
                    writer.Seek(0x8000, SeekOrigin.Begin);
                    writer.Write(ResourceHelper.GetResourceBytes("gdf_sector.bin"));
                    writer.Seek(0x10000, SeekOrigin.Begin);
                    writer.Write(magic);
                    writer.Write(rootDirSector);
                    writer.Write(rootDirSize * VolumeDescriptor.SectorSize);
                    writer.Write(VolumeDescriptor.ImageCreationTime);
                    writer.Write((byte)1);
                    writer.BaseStream.Seek(0x107EC, SeekOrigin.Begin);
                    writer.Write(magic);
                    writer.BaseStream.Seek(8, SeekOrigin.Begin);

                    var sectors = ((uint)(length / VolumeDescriptor.SectorSize));
                    length -= 0x400;
                    writer.Write(length);
                    writer.Seek(0x8050, SeekOrigin.Begin);
                    writer.Write(sectors);
                    writer.Write(sectors);
                }
            }

            Initialize(path);
        }
Ejemplo n.º 9
0
        public void WriteAllFiles(bool deleteRootFirst = false)
        {
            if (deleteRootFirst)
            {
                if (Directory.Exists(RootDir.ToPath()))
                {
                    Directory.Delete(RootDir.ToPath(), true);
                }
            }

            foreach (var cd in ClassFiles.Values)
            {
                if (!Directory.Exists(cd.Directory.ToPath()))
                {
                    Directory.CreateDirectory(cd.Directory.ToPath());
                }
                File.WriteAllText(cd.FilePath, cd);
            }

            foreach (var cd in InterfaceFiles.Values)
            {
                if (!Directory.Exists(cd.Directory.ToPath()))
                {
                    Directory.CreateDirectory(cd.Directory.ToPath());
                }
                File.WriteAllText(cd.FilePath, cd);
            }

            foreach (var cd in EnumFiles.Values)
            {
                if (!Directory.Exists(cd.Directory.ToPath()))
                {
                    Directory.CreateDirectory(cd.Directory.ToPath());
                }
                File.WriteAllText(cd.FilePath, cd);
            }

            foreach (var cd in UnionTypeDefinitions)
            {
                if (!Directory.Exists(cd.Directory.ToPath()))
                {
                    Directory.CreateDirectory(cd.Directory.ToPath());
                }
                File.WriteAllText(cd.FilePath, cd);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Raw data to save on host disk
        /// </summary>
        /// <returns></returns>
        public virtual byte[] ToRaw()
        {
            byte[] ret = new byte[Header.totalSectors * sectorSize];
            Header.Save(this);
            RootDir.Save(this);
            int current = 0;

            foreach (List <byte[]> trk in diskData)
            {
                foreach (byte[] sect in trk)
                {
                    Array.Copy(sect, 0, ret, current * sectorSize, sectorSize);
                    current++;
                }
            }
            return(ret);
        }
Ejemplo n.º 11
0
        public reloads_on_descriptor_change()
        {
            given_solution_addin_com_reg();

            given_solution_file("mySolution.sln", true);
            given_project_2010("MyProject");
            given_file("Class1.cs", "public class ClassName { public static void MainMethod() {} }");

            given_command("init-wrap . -name MyProject -all");
            given_vs_action(
                dte => dte.Solution.SaveAll(true),
                dte => dte.WaitForOutputMessage("OpenWrap", StartSolutionPlugin.SOLUTION_PLUGINS_STARTED, 1),
                dte => BumpPackageVersion(),
                dte => RootDir.GetFile("MyProject.wrapdesc").Touch(),
                dte => dte.WaitForOutputMessage("OpenWrap", StartSolutionPlugin.SOLUTION_PLUGINS_STARTED, 2));

            when_executing_vs2010();
        }
Ejemplo n.º 12
0
        private void Parse(uint tocOffset, int offset, string dirPrefix = null)
        {
            if (string.IsNullOrWhiteSpace(dirPrefix))
            {
                dirPrefix = Slash;
            }
            var data      = Read(tocOffset, 256, offset);
            var tableData = ModelFactory.GetModel <XisoTableData>(data);

            if (tableData.Sector == uint.MaxValue)
            {
                return;
            }

            if (tableData.Left != 0)
            {
                Parse(tocOffset, tableData.Left * 4, dirPrefix);
            }

            var file = new XisoFileEntry
            {
                TableData = tableData,
                Name      = tableData.Name,
                Flags     = tableData.Flags,
                Path      = dirPrefix + tableData.Name
            };

            RootDir.Insert(file.Path, file);
            if (tableData.IsDirectory)
            {
                file.Path += Slash;
                Parse(tableData.Sector, 0, file.Path);
            }
            else
            {
                file.Size   = tableData.Size;
                file.Offset = Type.SectorToOffset(tableData.Sector);
                ParseSpecial(file);
            }
            if (tableData.Right != 0)
            {
                Parse(tocOffset, tableData.Right * 4, dirPrefix);
            }
        }
Ejemplo n.º 13
0
        public virtual void Add(RootDir rootDir)
        {
            if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path))
            {
                throw new ArgumentException("Invalid path");
            }

            if (!_diskProvider.FolderExists(rootDir.Path))
            {
                throw new DirectoryNotFoundException("Can't add root directory that doesn't exist.");
            }

            if (GetAll().Exists(r => DiskProvider.PathEquals(r.Path, rootDir.Path)))
            {
                throw new InvalidOperationException("Root directory already exist.");
            }

            _database.Insert(rootDir);
        }
Ejemplo n.º 14
0
        private string GetProjectDirectory()
        {
            string projectPath = RootDir.Value();

            if (!Path.IsPathRooted(projectPath))
            {
                projectPath = Path.Combine(Directory.GetCurrentDirectory(), projectPath);
            }

            if (File.Exists(projectPath))
            {
                projectPath = Path.GetDirectoryName(projectPath);
            }

            if (!Directory.Exists(projectPath))
            {
                throw new DirectoryNotFoundException(string.Format(Resources.Text.DirectoryNotFoundMessage, projectPath));
            }

            return(projectPath);
        }
Ejemplo n.º 15
0
 public void PopulateSubDirs()
 {
     Nodes.Clear();
     try
     {
         foreach (var subDir in RootDir.GetDirectories())
         {
             Nodes.Add(new DirectoryNode(subDir, this));
         }
     }
     catch
     {
         HasError = true;
         SetImages();
         UpdateImage();
     }
     finally
     {
         ThisLevelEnumerated = true;
         UpdateImage();
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Sets up the arugments and options and also defines the operation
        /// executed by the command during execution.
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public virtual BaseCommand Configure(CommandLineApplication parent = null)
        {
            HelpOption("--help|-h");
            Verbosity = Option("--verbosity", Resources.Text.VerbosityOptionDesc, CommandOptionType.SingleValue);
            RootDir   = Option("--root", Resources.Text.ProjectPathOptionDesc, CommandOptionType.SingleValue);

            // Reserving this for now.
            RootDir.ShowInHelpText = false;

            OnExecute(async() =>
            {
                if (RootDir.HasValue())
                {
                    HostEnvironment.UpdateWorkingDirectory(GetProjectDirectory());
                }

                InitializeDependencies();
                return(await ExecuteInternalAsync());
            });
            Parent = parent;

            return(this);
        }
Ejemplo n.º 17
0
        private uint WriteDirectoryContents(BinaryWriter writer, string path, uint sector, out uint requiredSectors)
        {
            var tableEntries = RootDir.GetChildren(path)
                               .OrderBy(e => e.IsDirectory)
                               .Select(e => ModelFactory.GetModel <XisoTableData>(e.TableData.ReadAllBytes()))
                               .ToArray();
            var requiredSize = tableEntries.Sum(t => t.BinarySize);

            requiredSectors = RequiredSectors(requiredSize);
            var dataSector = sector + requiredSectors;
            var offset     = 0;

            for (var i = 0; i < tableEntries.Length; i++)
            {
                var t = tableEntries[i];
                t.Left  = 0;
                t.Right = i != tableEntries.Length - 1 ? (ushort)((offset + t.BinarySize) / 4) : (ushort)0;

                if (t.IsDirectory)
                {
                    t.Sector = dataSector;
                    uint innerTableSectors;
                    dataSector = WriteDirectoryContents(writer, path + t.Name + Slash, dataSector, out innerTableSectors);
                }
                else
                {
                    var data = Read(t.Sector, (int)t.Size);
                    t.Sector = dataSector;
                    WriteToSector(writer, dataSector, 0, data);
                    dataSector += RequiredSectors((int)t.Size);
                }
                WriteToSector(writer, sector, offset, t.ReadAllBytes());
                offset += t.BinarySize;
            }
            WriteToSector(writer, sector, offset, EmptySector, VolumeDescriptor.SectorSize * (int)requiredSectors - offset);
            return(dataSector);
        }
Ejemplo n.º 18
0
 public IEnumerable <XisoFileEntry> GetDirContents(string path)
 {
     return(RootDir.GetChildren(path));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Gets a file by Index
 /// </summary>
 /// <param name="index"></param>
 /// <returns>file in byte array</returns>
 public byte[] GetFile(Int32 index)
 {
     return(GetFile(RootDir.GetEntry(index)));
 }
Ejemplo n.º 20
0
 public string Relative(string path)
 {
     return(RootDir.Relative(path));
 }
Ejemplo n.º 21
0
        public string Relative(Func <MiruSolution, string> func)
        {
            var dir = func(this);

            return(RootDir.Relative(dir));
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Complete directory
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(string.Format("{0}\n{1}{2}", Header.ToString(), RootDir.ToString(), Header.PrintFreeSectors()));
 }
Ejemplo n.º 23
0
 public string ToStringLong()
 {
     return(Identifier + "(" + RootDir.ToString() + ")");
 }
Ejemplo n.º 24
0
 public override int GetHashCode()
 {
     return(RootDir != null ? RootDir.GetHashCode() : 0);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Gets a file by File Name
 /// </summary>
 /// <param name="filename"></param>
 /// <returns>file in byte array</returns>
 public byte[] GetFile(string filename)
 {
     return(GetFile(RootDir.GetEntry(filename)));
 }
Ejemplo n.º 26
0
 public string ToStringLong()
 {
     return(PackageIdPlayerFacing + "(" + RootDir.ToString() + ")");
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Load root directory
 /// </summary>
 protected virtual void LoadRoot()
 {
     RootDir.Load(this);
 }