private void InnerInstall(ManifestModuleInfo module, IProgress <ProgressMessage> progress)
        {
            var dstModuleDir  = Path.Combine(_modulesPath, module.Id);
            var moduleZipPath = Path.Combine(dstModuleDir, GetModuleZipFileName(module.Id, module.Version.ToString()));

            if (!Directory.Exists(dstModuleDir))
            {
                _txFileManager.CreateDirectory(dstModuleDir);
            }

            //download  module archive from web
            if (Uri.IsWellFormedUriString(module.Ref, UriKind.Absolute))
            {
                var moduleUrl = new Uri(module.Ref);

                using (var webClient = new WebClient())
                {
                    webClient.AddAuthorizationTokenForGitHub(moduleUrl);

                    using (var fileStream = File.OpenWrite(moduleZipPath))
                        using (var webStream = webClient.OpenRead(moduleUrl))
                        {
                            Report(progress, ProgressMessageLevel.Info, "Downloading '{0}' ", module.Ref);
                            webStream.CopyTo(fileStream);
                        }
                }
            }
            else if (File.Exists(module.Ref))
            {
                moduleZipPath = module.Ref;
            }

            using (var zipStream = File.Open(moduleZipPath, FileMode.Open))
                using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Read))
                {
                    foreach (var entry in archive.Entries.Where(e => !string.IsNullOrEmpty(e.Name)))
                    {
                        //Report(progress, ProgressMessageLevel.Info, "Extracting '{0}' ", entry.FullName);
                        var filePath = Path.Combine(dstModuleDir, entry.FullName);
                        //Create directory if not exist
                        var directoryPath = Path.GetDirectoryName(filePath);
                        if (!_txFileManager.DirectoryExists(directoryPath))
                        {
                            _txFileManager.CreateDirectory(directoryPath);
                        }
                        using (var entryStream = entry.Open())
                            using (var fileStream = File.Create(filePath))
                            {
                                entryStream.CopyTo(fileStream);
                            }
                        File.SetLastWriteTime(filePath, entry.LastWriteTime.LocalDateTime);
                    }
                }

            Report(progress, ProgressMessageLevel.Info, "Successfully installed '{0}'.", module);
        }
Beispiel #2
0
        static void RunStressTest()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            {
                // Pre-test checks
                string       tempDir;
                IFileManager fm = new TxFileManager();
                using (TransactionScope s1 = new TransactionScope())
                {
                    tempDir = (new DirectoryInfo(fm.CreateTempDirectory())).Parent.FullName;
                    Console.WriteLine("Temp path: " + tempDir);
                }

                string[] directories = Directory.GetDirectories(tempDir);
                string[] files       = Directory.GetFiles(tempDir);
                if (directories.Length > 0 || files.Length > 0)
                {
                    Console.WriteLine(string.Format("ERROR  Please ensure temp path {0} has no children before running this test.", tempDir));
                    return;
                }
            }

            // Start each test in its own thread and repeat for a few interations
            const int    numThreads = 10;
            const int    iterations = 250;
            const string text       = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            long count = 0;

            IList <Thread> threads = new List <Thread>();

            for (int i = 0; i < numThreads; i++)
            {
                Thread t = new Thread(() =>
                {
                    IFileManager fm = new TxFileManager();
                    for (int j = 0; j < iterations; j++)
                    {
                        using (TransactionScope s1 = new TransactionScope())
                        {
                            TransactionOptions to = new TransactionOptions();
                            to.Timeout            = TimeSpan.FromMinutes(30);

                            long myCount = Interlocked.Increment(ref count);
                            if (myCount % 250 == 0)
                            {
                                Console.WriteLine(myCount + " (" + myCount * 100 / (numThreads * iterations) + " %)");
                            }

                            string f1 = fm.CreateTempFileName();
                            string f2 = fm.CreateTempFileName();
                            string d1 = fm.CreateTempDirectory();

                            if (i % 100 == 0)
                            {
                                Console.WriteLine(i);
                            }

                            fm.AppendAllText(f1, text);
                            fm.Copy(f1, f2, false);

                            fm.CreateDirectory(d1);
                            fm.Delete(f2);
                            fm.DeleteDirectory(d1);
                            bool b1   = fm.DirectoryExists(d1);
                            bool b2   = fm.FileExists(f1);
                            string f3 = fm.CreateTempFileName();
                            fm.Move(f1, f3);
                            string f4 = fm.CreateTempFileName();
                            fm.Snapshot(f4);
                            fm.WriteAllBytes(f4, new byte[] { 64, 65 });
                            string f5 = fm.CreateTempFileName();
                            fm.WriteAllText(f5, text);

                            fm.Delete(f1);
                            fm.Delete(f2);
                            fm.Delete(f3);
                            fm.Delete(f4);
                            fm.Delete(f5);
                            fm.DeleteDirectory(d1);
                            s1.Complete();
                        }
                    }
                });

                threads.Add(t);
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            Console.WriteLine("All threads started.");

            foreach (Thread t in threads)
            {
                t.Join();
            }

            sw.Stop();

            Console.WriteLine("All threads joined. Elapsed: {0}.", sw.ElapsedMilliseconds);
        }
Beispiel #3
0
        // Moves files from AppData to current folder and vice versa
        // This is based off of the array below
        // Index 0 = Current Path
        // Index 1 = Default Path

        // Mode 0 = Current path -> Default Path (Turning off)
        // Mode 1 = Default path -> Current Path (Turning on)
        private void portibleModeToggle(int mode)
        {
            String[,] folderArray = new string[, ] {
                { Path.Combine(Paths.exeFolder, "config"), Paths.defaultConfigPath }, { Path.Combine(Paths.exeFolder, "Shortcuts"), Paths.defaultShortcutsPath }
            };
            String[,] fileArray = new string[, ] {
                { Path.Combine(Paths.exeFolder, "Taskbar Groups Background.exe"), Paths.defaultBackgroundPath }, { Path.Combine(Paths.exeFolder, "Settings.xml"), Settings.defaultSettingsPath }
            };

            int int1;
            int int2;

            if (mode == 0)
            {
                int1 = 0;
                int2 = 1;
            }
            else
            {
                int1 = 1;
                int2 = 0;
            }

            try
            {
                // Kill off the background process
                Process[] pname = Process.GetProcessesByName(Path.GetFileNameWithoutExtension("Taskbar Groups Background"));
                if (pname.Length != 0)
                {
                    pname[0].Kill();
                }

                IFileManager fm = new TxFileManager();
                using (TransactionScope scope1 = new TransactionScope())
                {
                    Settings.settingInfo.portableMode = true;
                    Settings.writeXML();

                    for (int i = 0; i < folderArray.Length / 2; i++)
                    {
                        if (fm.DirectoryExists(folderArray[i, int1]))
                        {
                            // Need to use another method to move from one partition to another
                            Microsoft.VisualBasic.FileIO.FileSystem.MoveDirectory(folderArray[i, int1], folderArray[i, int2]);

                            // Folders may still reside after being moved
                            if (fm.DirectoryExists(folderArray[i, int1]) && !Directory.EnumerateFileSystemEntries(folderArray[i, int1]).Any())
                            {
                                fm.DeleteDirectory(folderArray[i, int1]);
                            }
                        }
                        else
                        {
                            fm.CreateDirectory(folderArray[i, int2]);
                        }
                    }

                    for (int i = 0; i < fileArray.Length / 2; i++)
                    {
                        if (fm.FileExists(fileArray[i, int1]))
                        {
                            fm.Move(fileArray[i, int1], fileArray[i, int2]);
                        }
                    }

                    if (mode == 0)
                    {
                        Paths.ConfigPath            = Paths.defaultConfigPath;
                        Paths.ShortcutsPath         = Paths.defaultShortcutsPath;
                        Paths.BackgroundApplication = Paths.defaultBackgroundPath;
                        Settings.settingsPath       = Settings.defaultSettingsPath;

                        portabilityButton.Tag   = "n";
                        portabilityButton.Image = Properties.Resources.toggleOff;
                    }
                    else
                    {
                        Paths.ConfigPath    = folderArray[0, 0];
                        Paths.ShortcutsPath = folderArray[1, 0];

                        Paths.BackgroundApplication = fileArray[0, 0];
                        Settings.settingsPath       = fileArray[1, 0];

                        portabilityButton.Tag   = "y";
                        portabilityButton.Image = Properties.Resources.toggleOn;
                    }

                    changeAllShortcuts();


                    scope1.Complete();

                    MessageBox.Show("File moving done!");
                }
            }
            catch (IOException e) {
                MessageBox.Show("The application does not have access to this directory!\r\n\r\nError: " + e.Message);
            }
        }