Example #1
0
        private VfsEntry ResolveParent(TEntry entry, VfsEntry root)
        {
            var path            = SanitizePath(entry.Key);
            var targetEntryName = GetEntryName(path);
            var pathParts       = path.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);

            VfsEntry currentEntry = root;

            foreach (var part in pathParts)
            {
                if (part == targetEntryName)
                {
                    break;
                }

                if (!currentEntry.TryGetChild(part, out var targetEntry))
                {
                    targetEntry = new ArchiveDirectory(part, this, currentEntry);
                }

                currentEntry = targetEntry;
            }

            return(currentEntry);
        }
        private void Log(ArchiveDirectory dir, StringBuilder builder, string prefix)
        {
            int fc = 0;

            foreach (var f in dir.Files)
            {
                string p = (fc++ == dir.Files.Count - 1 && dir.Directories.Count == 0) ? "└─ " : "├─ ";

                builder.Append(prefix);
                builder.Append(p);
                builder.AppendLine(f.Value.Name);
            }

            int dc = 0;

            foreach (var d in dir.Directories)
            {
                string p1 = dc == dir.Directories.Count - 1 ? "└─ " : "├─ ";
                string p2 = dc == dir.Directories.Count - 1 ? "   " : "│  ";
                dc++;

                builder.Append(prefix);
                builder.Append(p1);
                builder.AppendLine(d.Value.Name);

                Log(d.Value, builder, prefix + p2);
            }
        }
Example #3
0
        public void OnNavigatedTo(NavigationContext context)
        {
            try
            {
                _archiveType     = (ArchiveType)context.Parameters["archiveType"];
                _archiveFileName = (string)context.Parameters["archiveFileName"];

                _testSession = Directory.Exists(_archiveFileName)
                    ? _arkadeApi.CreateTestSession(ArchiveDirectory.Read(_archiveFileName, _archiveType))
                    : _arkadeApi.CreateTestSession(ArchiveFile.Read(_archiveFileName, _archiveType));

                if (!_testSession.IsTestableArchive())
                {
                    _statusEventHandler.RaiseEventOperationMessage(
                        Resources.GUI.TestrunnerArchiveTestability,
                        string.Format(Resources.GUI.TestrunnerArchiveNotTestable, ArkadeProcessingArea.LogsDirectory),
                        OperationMessageStatus.Warning
                        );
                }

                StartTestingCommand.RaiseCanExecuteChanged(); // testSession has been updated, reevaluate command
            }
            catch (Exception e)
            {
                string message = string.Format(Resources.GUI.ErrorReadingArchive, e.Message);
                Log.Error(e, message);
                _statusEventHandler.RaiseEventOperationMessage(null, message, OperationMessageStatus.Error);
            }
        }
Example #4
0
        /// <summary>
        /// 指定したコンテナとdirectory以下のBlob一覧とメタデータを取得する。
        /// </summary>
        /// <param name="directory">ディレクトリ</param>
        /// <returns>ファイル一覧</returns>
        public IEnumerable <ArchiveFile> GetArchiveFiles(ArchiveDirectory directory)
        {
            _log.EnterJson("ArchiveDirectory: {0}", directory);

            Assert.IfNull(directory);
            CloudBlobContainer container     = _collectingBlob.GetContainerReadOnly(directory.ContainerName ?? string.Empty);
            CloudBlobDirectory blobDirectory = container.GetDirectoryReference(directory.DirectoryPath);
            var blobs = new List <CloudBlockBlob>();

            _polly.Execute(
                () =>
            {
                var token = default(BlobContinuationToken);
                do
                {
                    // Blob一覧を取得
                    BlobResultSegment segment = null;

                    // 指定しない場合上限の5000件ずつ取得される
                    segment = blobDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, token, null, null).Result;

                    token = segment.ContinuationToken;
                    blobs.AddRange(segment.Results.OfType <CloudBlockBlob>());
                }while (token != null);
            });

            return(blobs.Select(blob => Blob.BlobToArchiveFile(blob)));
        }
        public virtual void LoadToggleData(StorageDirectory holderAppDataFolder)
        {
            DataFolder = new StorageDirectory(holderAppDataFolder.RelativePathParts.Merge(Id));
            if (FileStorageManager.Instance.DataState == DataActualityState.Updated ||
                FileStorageManager.Instance.UseLocalMode)
            {
                return;
            }

            AsyncHelper.RunSync(async() =>
            {
                var templateVersionFile = new StorageFile(DataFolder.RelativePathParts.Merge("version.txt"));
                if (!await templateVersionFile.Exists(true) || await templateVersionFile.IsOutOfDate())
                {
                    await DataFolder.Allocate(false);
                    if (await DataFolder.Exists(true))
                    {
                        var templateFiles = (await DataFolder.GetRemoteFiles()).ToList();
                        foreach (var templateFile in templateFiles)
                        {
                            if (templateFile.Name.Contains(".rar"))
                            {
                                var archiveFolder = new ArchiveDirectory(DataFolder.RelativePathParts.Merge(templateFile.NameOnly));
                                await archiveFolder.Download();
                            }
                            else
                            {
                                await templateFile.Download();
                            }
                        }
                    }
                }
            });
        }
Example #6
0
        private void _add(object obj)
        {
            var newDir = new ArchiveDirectory();

            Directories.Add(newDir);
            Model.Directories.Add(newDir);
            SelectedDirectory = newDir;
        }
        private string Log(ArchiveDirectory dir)
        {
            var builder = new StringBuilder();

            builder.AppendLine(dir.FullName);

            Log(dir, builder, "");
            return(builder.ToString());
        }
        public async Task Load()
        {
            await Asa.Common.Core.Configuration.ResourceManager.Instance.LoadSubStorageIndependentResources();

            await Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.Download();

            DataUsersFile = new StorageFile(
                Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.RelativePathParts.Merge("Users.xml"));

            DataCoverFile = new StorageFile(
                Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.RelativePathParts.Merge("Add Cover.xml"));

            DataClientGoalsFile = new StorageFile(
                Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.RelativePathParts.Merge("Needs Analysis.xml"));

            DataLeadoffStatementFile = new StorageFile(
                Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.RelativePathParts.Merge("Intro Slide.xml"));

            DataTargetCustomersFile = new StorageFile(
                Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.RelativePathParts.Merge("Target Customer.xml"));

            TextResourcesFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "app_branding.xml"
            });
            if (await TextResourcesFile.Exists(true))
            {
                await TextResourcesFile.Download();
            }

            ImageResourcesFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources"
            });
            if (await ImageResourcesFolder.Exists(true))
            {
                await ImageResourcesFolder.Download();
            }

            FormStyleConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "style.xml"
            });
            if (await FormStyleConfigFile.Exists(true))
            {
                await FormStyleConfigFile.Download();
            }
        }
Example #9
0
        private async Task ArchiveReport(Report report)
        {
            reloadTask.Wait();

            await Task.Run(() =>
            {
                FileInfo reportInfo          = new FileInfo(report.Path);
                FileInfo generatedReportInfo = new FileInfo(Path.Combine(reportInfo.Directory.FullName, report.GetGeneratedReportName()));

                DateTime now = DateTime.Now;

                // Check if archiving is needed
                if (generatedReportInfo.Exists)
                {
                    DateTime oldArchiveDate = Utils.RoundDateTime(generatedReportInfo.LastWriteTime, report.ArchiveTime);
                    DateTime newArchiveDate = Utils.RoundDateTime(now, report.ArchiveTime);

                    if (newArchiveDate != oldArchiveDate)
                    {
                        string archiveName   = GetArchiveName(oldArchiveDate);
                        FileInfo archiveInfo = new FileInfo(Path.Combine(ArchiveDirectory.FullName, archiveName));

                        if (!ArchiveDirectory.Exists)
                        {
                            ArchiveDirectory.Create();
                        }

                        if (!archiveInfo.Exists)
                        {
                            using (FileStream archiveStream = archiveInfo.Create())
                                using (ZipArchive archive = new ZipArchive(archiveStream, ZipArchiveMode.Create))
                                    archive.ToString();
                        }

                        using (FileStream archiveStream = archiveInfo.Open(FileMode.Open))
                            using (ZipArchive archive = new ZipArchive(archiveStream, ZipArchiveMode.Update))
                            {
                                string reportArchiveName = report.GetArchivedReportName(oldArchiveDate);

                                ZipArchiveEntry reportArchiveEntry = archive.GetEntry(reportArchiveName);
                                if (reportArchiveEntry == null)
                                {
                                    reportArchiveEntry = archive.CreateEntry(reportArchiveName, CompressionLevel.Optimal);

                                    using (FileStream reportStream = generatedReportInfo.OpenRead())
                                        using (Stream reportArchiveStream = reportArchiveEntry.Open())
                                            reportStream.CopyTo(reportArchiveStream);
                                }
                            }
                    }
                }
            });

            await CleanArchives(report);
        }
Example #10
0
        private async Task ExtractTabContent()
        {
            if (FileStorageManager.Instance.DataState == DataActualityState.Updated)
            {
                return;
            }
            var tabConfigFiles =
                (await ResourceManager.Instance.DataFolder.GetRemoteFiles(itemName => itemName.Contains("tab_"))).ToList();

            foreach (var tabConfigName in tabConfigFiles.Select(file => Regex.Match(file.Name, @"^.*?(?=\.)").Value).Distinct())
            {
                var archiveFolder = new ArchiveDirectory(ResourceManager.Instance.DataFolder.RelativePathParts.Merge(tabConfigName));
                await archiveFolder.Download();
            }
        }
Example #11
0
        public TestSession NewSession(ArchiveDirectory archiveDirectory)
        {
            ReadingArchiveStartedEvent();

            ArchiveType archiveType = archiveDirectory.ArchiveType;

            _log.Information(
                $"Building new TestSession from directory [archiveType: {archiveType}] [directory: {archiveDirectory.Directory.FullName}]");

            Uuid uuid = Uuid.Random();

            ArchiveInformationEvent(archiveDirectory.Directory.FullName, archiveType, uuid);
            WorkingDirectory workingDirectory = WorkingDirectory.FromUuid(uuid, archiveDirectory.Directory);

            TestSession testSession = NewSession(workingDirectory, archiveType, uuid);

            ReadingArchiveFinishedEvent();
            return(testSession);
        }
Example #12
0
        private static TestSession CreateTestSession(CommandLineOptions options, Core.Arkade arkade, ArchiveType archiveType)
        {
            TestSession testSession;

            if (File.Exists(options.Archive))
            {
                Log.Debug("File exists");
                testSession = arkade.RunTests(ArchiveFile.Read(options.Archive, archiveType));
            }
            else if (Directory.Exists(options.Archive))
            {
                Log.Debug("Directory exists");
                testSession = arkade.RunTests(ArchiveDirectory.Read(options.Archive, archiveType));
            }
            else
            {
                throw new ArgumentException("Invalid archive path: " + options.Archive);
            }
            return(testSession);
        }
Example #13
0
        protected override VfsDirectory BuildFileHierarchy()
        {
            _archiveStream.Seek(0, SeekOrigin.Begin);
            var root = new ArchiveDirectory(this);

            foreach (var entry in _archive.Entries)
            {
                if (entry.IsDirectory)
                {
                    continue;
                }

                if (entry == null || entry.Key == null)
                {
                    continue;
                }

                var parent = ResolveParent(entry, root);
                new ArchiveFile(entry, this, parent);
            }

            return(root);
        }
Example #14
0
        /// <summary>
        /// Erzeugt eine neue Verwaltungsinstanz und lädt die aktuellen Auftragsliste.
        /// </summary>
        /// <param name="rootDirectory">Meldet das Verzeichnis, unterhalb dessen alle
        /// Aufträge und Protokolle angelegt werden.</param>
        /// <param name="server">Die VCR.NET Instanz, der diese Verwaltung zugeordnet ist.</param>
        internal JobManager(DirectoryInfo rootDirectory, VCRServer server)
        {
            // Remember
            RootDirectory = rootDirectory;
            Server        = server;

            // Create root directory
            RootDirectory.Create();

            // Create working directories
            CollectorDirectory.Create();
            ArchiveDirectory.Create();
            JobDirectory.Create();
            LogDirectory.Create();

            // Load all jobs
            foreach (var job in VCRJob.Load(JobDirectory))
            {
                if (job.UniqueID.HasValue)
                {
                    m_Jobs[job.UniqueID.Value] = job;
                }
            }
        }
        public async Task LoadSubStorageDependentResources()
        {
            var folderNameParts = !String.IsNullOrEmpty(AppProfileManager.Instance.SubStorageName)
                ? new[]
            {
                FileStorageManager.IncomingFolderName,
                $"{FileStorageManager.CommonIncomingFolderName}_clients",
                AppProfileManager.Instance.SubStorageName,
            }
                : new[]
            {
                FileStorageManager.IncomingFolderName,
                FileStorageManager.CommonIncomingFolderName,
            };

            #region Remote
            DictionariesFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "ad_sales_data"
            }));

            MasterWizardsFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "Slides"
            }));
            await MasterWizardsFolder.Download();

            ThemesFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "SellerPointThemes"
            }));
            await ThemesFolder.Download();

            SlideMastersFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "SlidesTab"
            }));
            if (await SlideMastersFolder.Exists(true))
            {
                await SlideMastersFolder.Download();
            }

            ScheduleSlideTemplatesFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "ScheduleBuilders"
            }));

            CalendarSlideTemplatesFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "Calendar"
            }));

            ArtworkFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "Artwork"
            }));

            RateCardFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "RateCard"
            }));

            DefaultSlideSettingsFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "DefaultSlideSettings.xml"
            }));
            await DefaultSlideSettingsFile.Download();

            SlideSizeSettingsFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "SlideSizeSettings.xml"
            }));
            await SlideSizeSettingsFile.Download();

            HelpFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "HelpUrls",
                HelpManager.GetFileName()
            }));
            await HelpFile.Download();

            HelpBrowserFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "HelpUrls",
                "!Help_Browser.xml"
            }));
            await HelpBrowserFile.Download();

            OnlineListsFile = new StorageFile(
                DictionariesFolder.RelativePathParts.Merge("Online Strategy.xml"));

            DataSimpleSummaryFile = new StorageFile(
                DictionariesFolder.RelativePathParts.Merge("Closing Summary.xml"));

            #endregion
        }
Example #16
0
        public Task CleanArchives(Report report)
        {
            return(Task.Run(() =>
            {
                DateTime deleteTime = DateTime.Now - report.DeleteTime;

                FileInfo[] archivesInfo = ArchiveDirectory.GetFiles();
                foreach (FileInfo archiveInfo in archivesInfo)
                {
                    Match archiveName = ArchiveRegex.Match(archiveInfo.Name);
                    if (!archiveName.Success)
                    {
                        continue;
                    }

                    DateTime archiveDate;
                    if (!DateTime.TryParse(archiveName.Groups["Date"].Value, out archiveDate))
                    {
                        continue;
                    }

                    if (archiveDate > deleteTime.Date)
                    {
                        continue;
                    }

                    bool deleteArchive = false;

                    using (FileStream archiveStream = archiveInfo.Open(FileMode.Open))
                        using (ZipArchive archive = new ZipArchive(archiveStream, ZipArchiveMode.Update))
                        {
                            foreach (ZipArchiveEntry archiveEntry in archive.Entries.ToArray())
                            {
                                Match reportArchiveName = ReportArchiveRegex.Match(archiveEntry.Name);
                                if (!reportArchiveName.Success)
                                {
                                    continue;
                                }

                                DateTime reportArchiveDate;
                                if (!DateTime.TryParse(reportArchiveName.Groups["Date"].Value, out reportArchiveDate))
                                {
                                    continue;
                                }

                                if (reportArchiveDate > deleteTime)
                                {
                                    continue;
                                }

                                if (archiveEntry.Name != report.GetArchivedReportName(reportArchiveDate))
                                {
                                    continue;
                                }

                                archiveEntry.Delete();
                            }

                            deleteArchive = archive.Entries.Count == 0;
                        }

                    if (deleteArchive)
                    {
                        archiveInfo.Delete();
                    }
                }
            }));
        }
Example #17
0
        public async Task Load()
        {
            #region Local
            TempFolder = new StorageDirectory(new[]
            {
                "Temp"
            });
            if (!await TempFolder.Exists())
            {
                await StorageDirectory.CreateSubFolder(new string[] { }, "Temp");
            }

            AppSettingsFolder = new StorageDirectory(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                AppProfileManager.Instance.AppSubStorageDependentFolderName,
            });
            if (!await AppSettingsFolder.Exists())
            {
                await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, AppProfileManager.Instance.AppSubStorageIndependentFolderName);
            }

            AppSettingsFile = new StorageFile(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Settings.xml"
            });
            AppSettingsFile.AllocateParentFolder();
            #endregion

            #region Remote
            AppConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "Config.xml"
            });
            await AppConfigFile.Download();

            TabsConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "TabNames.xml"
            });
            await TabsConfigFile.Download();

            WatchedProcessesFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "HideList.xml"
            });
            await WatchedProcessesFile.Download();

            MaintenanceConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "maintenance.xml"
            });
            if (await MaintenanceConfigFile.Exists(true))
            {
                await MaintenanceConfigFile.Download();
            }

            PatchUpdaterConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "sfx_update.xml"
            });
            if (await PatchUpdaterConfigFile.Exists(true))
            {
                await PatchUpdaterConfigFile.Download();
            }

            UpdaterConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "AppSettings",
                "updater.xml"
            });
            if (await UpdaterConfigFile.Exists(true))
            {
                await UpdaterConfigFile.Download();
            }

            NoSyncConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "NoSync.xml"
            });
            if (await NoSyncConfigFile.Exists(true))
            {
                await NoSyncConfigFile.Download();
            }

            SyncFormColorConfigFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "sync_color.xml"
            });
            if (await SyncFormColorConfigFile.Exists(true))
            {
                await SyncFormColorConfigFile.Download();
            }

            IconFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "icon.ico"
            });
            if (await IconFile.Exists(true))
            {
                await IconFile.Download();
            }

            LoginLogoFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "app_logo.png"
            });
            if (await LoginLogoFile.Exists(true))
            {
                await LoginLogoFile.Download();
            }

            SplashLogoFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "splash_logo.png"
            });
            if (await SplashLogoFile.Exists(true))
            {
                await SplashLogoFile.Download();
            }

            SyncFormCloseImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "ProgressCancel.png"
            });
            if (await SyncFormCloseImageFile.Exists(true))
            {
                await SyncFormCloseImageFile.Download();
            }

            UndockFormImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "undock_arrow.png"
            });
            if (await UndockFormImageFile.Exists(true))
            {
                await UndockFormImageFile.Download();
            }

            DockRegularImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "dock_arrow_ribbon.png"
            });
            if (await DockRegularImageFile.Exists(true))
            {
                await DockRegularImageFile.Download();
            }

            DockFloaterImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "dock_arrow_floater.png"
            });
            if (await DockFloaterImageFile.Exists(true))
            {
                await DockFloaterImageFile.Download();
            }

            ExpandFormImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "undocked_expand.png"
            });
            if (await ExpandFormImageFile.Exists(true))
            {
                await ExpandFormImageFile.Download();
            }

            CollapseFormImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "undocked_collapse.png"
            });
            if (await CollapseFormImageFile.Exists(true))
            {
                await CollapseFormImageFile.Download();
            }

            FloaterLogoFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "collapsed_undocked_logo.png"
            });
            if (await FloaterLogoFile.Exists(true))
            {
                await FloaterLogoFile.Download();
            }

            FloaterCancelImageFile = new StorageFile(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Resources",
                "undockedCancel.png"
            });
            if (await FloaterCancelImageFile.Exists(true))
            {
                await FloaterCancelImageFile.Download();
            }

            SharedAssembliesFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                FileStorageManager.CommonIncomingFolderName,
                "SharedAssemblies"
            });
            if (await SharedAssembliesFolder.Exists(true))
            {
                await SharedAssembliesFolder.DownloadTo(SharedAssemblyHelper.SharedAssemblyLocationPath);
            }

            SpecialAppsFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                FileStorageManager.CommonIncomingFolderName,
                "SpecialApps"
            });
            if (await SpecialAppsFolder.Exists(true))
            {
                await SpecialAppsFolder.Download();
            }

            DataFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Data",
            });

            SyncFilesFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Data",
                "SyncFiles"
            });
            if (await SyncFilesFolder.Exists(true))
            {
                await SyncFilesFolder.Download();
            }

            CloudFilesFolder = new StorageDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                FileStorageManager.CommonIncomingFolderName,
                "CloudFiles",
            });
            #endregion

            #region Make local copy
            if (NoSyncConfigFile.ExistsLocal())
            {
                File.Copy(NoSyncConfigFile.LocalPath, Path.Combine(AppRootFolderPath, Path.GetFileName(NoSyncConfigFile.LocalPath)), true);
            }
            if (UpdaterConfigFile.ExistsLocal())
            {
                File.Copy(UpdaterConfigFile.LocalPath, Path.Combine(AppRootFolderPath, Path.GetFileName(UpdaterConfigFile.LocalPath)), true);
            }
            if (SyncFormColorConfigFile.ExistsLocal())
            {
                File.Copy(SyncFormColorConfigFile.LocalPath, Path.Combine(AppRootFolderPath, Path.GetFileName(SyncFormColorConfigFile.LocalPath)), true);
            }
            if (IconFile.ExistsLocal())
            {
                File.Copy(IconFile.LocalPath, Path.Combine(AppRootFolderPath, Path.GetFileName(IconFile.LocalPath)), true);
            }
            if (LoginLogoFile.ExistsLocal())
            {
                File.Copy(LoginLogoFile.LocalPath, Path.Combine(AppRootFolderPath, Path.GetFileName(LoginLogoFile.LocalPath)), true);
            }
            if (SyncFormCloseImageFile.ExistsLocal())
            {
                File.Copy(SyncFormCloseImageFile.LocalPath, Path.Combine(AppRootFolderPath, Path.GetFileName(SyncFormCloseImageFile.LocalPath)), true);
            }
            #endregion
        }
Example #18
0
        private void RunTests()
        {
            try
            {
                NotifyStartRunningTests();

                if (Directory.Exists(_archiveFileName))
                {
                    _testSession = _arkadeApi.RunTests(ArchiveDirectory.Read(_archiveFileName, _archiveType));
                }
                else
                {
                    _testSession = _arkadeApi.RunTests(ArchiveFile.Read(_archiveFileName, _archiveType));
                }

                _testSession.TestSummary = new TestSummary(_numberOfProcessedFiles, _numberOfProcessedRecords, _numberOfTestsFinished);

                _testSession.AddLogEntry("Test run completed.");

                SaveHtmlReport();

                _testRunCompletedSuccessfully = true;
                _statusEventHandler.RaiseEventOperationMessage(Resources.UI.TestrunnerFinishedOperationMessage, null, OperationMessageStatus.Ok);
                NotifyFinishedRunningTests();
            }
            catch (ArkadeException e)
            {
                _testSession?.AddLogEntry("Test run failed: " + e.Message);
                _log.Error(e.Message, e);
                _statusEventHandler.RaiseEventOperationMessage(Resources.UI.TestrunnerFinishedWithError, e.Message, OperationMessageStatus.Error);
                NotifyFinishedRunningTests();
            }
            catch (Exception e)
            {
                _testSession?.AddLogEntry("Test run failed: " + e.Message);
                _log.Error(e.Message, e);

                var operationMessageBuilder = new StringBuilder();

                if (e.GetType() == typeof(FileNotFoundException))
                {
                    string nameOfMissingFile = new FileInfo(((FileNotFoundException)e).FileName).Name;
                    operationMessageBuilder.Append(string.Format(Resources.UI.FileNotFoundMessage, nameOfMissingFile));
                }
                else
                {
                    operationMessageBuilder.Append(e.Message);
                }

                string fileName = new DetailedExceptionMessage(e).WriteToFile();

                if (!string.IsNullOrEmpty(fileName))
                {
                    operationMessageBuilder.AppendLine("\n" + string.Format(Resources.UI.DetailedErrorMessageInfo, fileName));
                }

                string operationMessage = operationMessageBuilder.ToString();

                _statusEventHandler.RaiseEventOperationMessage(
                    Resources.UI.TestrunnerFinishedWithError, operationMessage, OperationMessageStatus.Error
                    );

                NotifyFinishedRunningTests();
            }
        }
Example #19
0
        private IEnumerable <List <GrepSearchResult> > SearchInsideArchive(Stream input, string fileName,
                                                                           string searchPattern, SearchType searchType, GrepSearchOption searchOptions, Encoding encoding)
        {
            using (SevenZipExtractor extractor = new SevenZipExtractor(input, true))
            {
                foreach (var fileInfo in extractor.ArchiveFileData)
                {
                    FileData fileData = new FileData(fileName, fileInfo);

                    var    attr          = (FileAttributes)fileInfo.Attributes;
                    string innerFileName = fileInfo.FileName;

                    int index = fileInfo.Index;
                    if (innerFileName == "[no name]" && extractor.ArchiveFileData.Count == 1)
                    {
                        index         = 0;
                        innerFileName = Path.GetFileNameWithoutExtension(fileName);
                        ArchiveFileInfo temp = ArchiveDirectory.Copy(fileInfo);
                        temp.FileName = innerFileName;
                        fileData      = new FileData(fileName, temp);
                    }

                    if (fileInfo.IsDirectory)
                    {
                        if (!fileFilter.IncludeHidden && attr.HasFlag(FileAttributes.Hidden) &&
                            !hiddenDirectories.Contains(innerFileName))
                        {
                            hiddenDirectories.Add(innerFileName + Path.DirectorySeparator);
                        }

                        continue;
                    }

                    if (!fileFilter.IncludeHidden)
                    {
                        if (attr.HasFlag(FileAttributes.Hidden))
                        {
                            continue;
                        }

                        bool excludeFile = false;
                        foreach (string dir in hiddenDirectories)
                        {
                            if (innerFileName.StartsWith(dir))
                            {
                                excludeFile = true;
                                break;
                            }
                        }

                        if (excludeFile)
                        {
                            continue;
                        }
                    }

                    if (Utils.IsArchive(innerFileName))
                    {
                        using (Stream stream = new MemoryStream(4096))
                        {
                            extractor.ExtractFile(index, stream);

                            var enumerator = SearchInsideArchive(stream, fileName + ArchiveDirectory.ArchiveSeparator + innerFileName,
                                                                 searchPattern, searchType, searchOptions, encoding).GetEnumerator();

                            while (true)
                            {
                                List <GrepSearchResult> ret = null;
                                try
                                {
                                    if (!enumerator.MoveNext())
                                    {
                                        break;
                                    }
                                    ret = enumerator.Current;
                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format(CultureInfo.CurrentCulture, "Failed to search inside archive '{0}'", fileName + ArchiveDirectory.ArchiveSeparator + innerFileName);
                                    logger.Error(ex, msg);

                                    fileData.ErrorMsg = msg + ": " + ex.Message;
                                    ret = new List <GrepSearchResult> {
                                        new GrepSearchResult(fileData, encoding)
                                    };
                                }
                                if (ret != null)
                                {
                                    yield return(ret);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (ArchiveDirectory.IncludeFile(innerFileName,
                                                         fileName + ArchiveDirectory.ArchiveSeparator + innerFileName,
                                                         fileFilter, fileData, includeSearchPatterns,
                                                         includeRegexPatterns, excludeRegexPatterns))
                        {
                            var res = SearchInnerFile(extractor, index, fileFilter, fileData,
                                                      fileName + ArchiveDirectory.ArchiveSeparator + innerFileName,
                                                      searchPattern, searchType, searchOptions, encoding);

                            if (res != null)
                            {
                                yield return(res);
                            }
                        }
                    }
                    if (Utils.CancelSearch)
                    {
                        break;
                    }
                }
            }
        }
Example #20
0
        private void SaveSettings()
        {
            if (EnableWindowsIntegration)
            {
                ShellRegister("Directory");
                ShellRegister("Drive");
                ShellRegister("*");
                ShellRegister("here");
            }
            else
            {
                ShellUnregister("Directory");
                ShellUnregister("Drive");
                ShellUnregister("*");
                ShellUnregister("here");
            }

            if (EnableStartupAcceleration)
            {
                StartupRegister();
            }
            else
            {
                StartupUnregister();
            }

            ApplicationFontFamily = EditApplicationFontFamily;
            MainFormFontSize      = EditMainFormFontSize;
            ReplaceFormFontSize   = EditReplaceFormFontSize;
            DialogFontSize        = EditDialogFontSize;

            Settings.Set(GrepSettings.Key.EnableUpdateChecking, EnableCheckForUpdates);
            Settings.Set(GrepSettings.Key.UpdateCheckInterval, CheckForUpdatesInterval);
            Settings.Set(GrepSettings.Key.CustomEditor, CustomEditorPath);
            Settings.Set(GrepSettings.Key.CustomEditorArgs, CustomEditorArgs);
            Settings.Set(GrepSettings.Key.CompareApplication, CompareApplicationPath);
            Settings.Set(GrepSettings.Key.CompareApplicationArgs, CompareApplicationArgs);
            Settings.Set(GrepSettings.Key.ShowFilePathInResults, ShowFilePathInResults);
            Settings.Set(GrepSettings.Key.AllowSearchingForFileNamePattern, AllowSearchWithEmptyPattern);
            Settings.Set(GrepSettings.Key.DetectEncodingForFileNamePattern, DetectEncodingForFileNamePattern);
            Settings.Set(GrepSettings.Key.ExpandResults, AutoExpandSearchTree);
            Settings.Set(GrepSettings.Key.ShowVerboseMatchCount, ShowVerboseMatchCount);
            Settings.Set(GrepSettings.Key.ShowFileInfoTooltips, ShowFileInfoTooltips);
            Settings.Set(GrepSettings.Key.MatchTimeout, MatchTimeout);
            Settings.Set(GrepSettings.Key.FuzzyMatchThreshold, MatchThreshold);
            Settings.Set(GrepSettings.Key.ShowLinesInContext, ShowLinesInContext);
            Settings.Set(GrepSettings.Key.ContextLinesBefore, ContextLinesBefore);
            Settings.Set(GrepSettings.Key.ContextLinesAfter, ContextLinesAfter);
            Settings.Set(GrepSettings.Key.MaxSearchBookmarks, MaxSearchBookmarks);
            Settings.Set(GrepSettings.Key.MaxPathBookmarks, MaxPathBookmarks);
            Settings.Set(GrepSettings.Key.MaxExtensionBookmarks, MaxExtensionBookmarks);
            Settings.Set(GrepSettings.Key.OptionsOnMainPanel, OptionsLocation == PanelSelection.MainPanel);
            Settings.Set(GrepSettings.Key.FollowWindowsTheme, FollowWindowsTheme);
            Settings.Set(GrepSettings.Key.CurrentTheme, CurrentTheme);
            Settings.Set(GrepSettings.Key.UseDefaultFont, UseDefaultFont);
            Settings.Set(GrepSettings.Key.ApplicationFontFamily, ApplicationFontFamily);
            Settings.Set(GrepSettings.Key.MainFormFontSize, MainFormFontSize);
            Settings.Set(GrepSettings.Key.ReplaceFormFontSize, ReplaceFormFontSize);
            Settings.Set(GrepSettings.Key.DialogFontSize, DialogFontSize);
            Settings.Set(GrepSettings.Key.PdfToTextOptions, PdfToTextOptions);

            if (ArchiveOptions.IsChanged)
            {
                string nameKey = "Archive";
                string addKey  = "Add" + nameKey + "Extensions";
                string remKey  = "Rem" + nameKey + "Extensions";

                Settings.Set(addKey, CleanExtensions(ArchiveOptions.AddExtensions));
                Settings.Set(remKey, CleanExtensions(ArchiveOptions.RemExtensions));

                ArchiveOptions.SetUnchanged();
                ArchiveDirectory.Reinitialize();
            }

            bool pluginsChanged = Plugins.Any(p => p.IsChanged);

            foreach (var plugin in Plugins)
            {
                string nameKey    = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(plugin.Name);
                string enabledkey = nameKey + "Enabled";
                string addKey     = "Add" + nameKey + "Extensions";
                string remKey     = "Rem" + nameKey + "Extensions";

                Settings.Set(enabledkey, plugin.IsEnabled);
                Settings.Set(addKey, CleanExtensions(plugin.AddExtensions));
                Settings.Set(remKey, CleanExtensions(plugin.RemExtensions));

                plugin.SetUnchanged();
            }

            Settings.Save();

            if (pluginsChanged)
            {
                GrepEngineFactory.ReloadPlugins();
            }
        }
Example #21
0
        private List <GrepSearchResult> SearchInnerFile(SevenZipExtractor extractor, int index,
                                                        FileFilter fileFilter, FileData fileData, string innerFileName, string searchPattern,
                                                        SearchType searchType, GrepSearchOption searchOptions, Encoding encoding)
        {
            List <GrepSearchResult> innerFileResults = null;

            try
            {
                using (Stream stream = new MemoryStream(4096))
                {
                    extractor.ExtractFile(index, stream);
                    stream.Seek(0, SeekOrigin.Begin);

                    if (!ArchiveDirectory.IncludeFileStream(stream,
                                                            fileFilter, fileData, true, includeShebangPatterns))
                    {
                        return(innerFileResults);
                    }

                    // The IncludeFileStream method determined the encoding of the file in the archive.
                    // If the encoding parameter is not default then it is the user-specified code page.
                    // If the encoding parameter *is* the default, then it most likely not been set, so
                    // use the encoding of the extracted text file
                    if (encoding == Encoding.Default && !fileData.IsBinary)
                    {
                        encoding = fileData.Encoding;
                    }

                    StartingFileSearch?.Invoke(this, new DataEventArgs <string>(innerFileName));

                    IGrepEngine engine = GrepEngineFactory.GetSearchEngine(innerFileName, searchParams, fileFilter, searchType);
                    innerFileResults = engine.Search(stream, innerFileName, searchPattern, searchType, searchOptions, encoding);

                    if (innerFileResults.Any())
                    {
                        if (precacheResults)
                        {
                            // pre-cache the search results since the text is available.
                            // user has set the option to auto-expand the results tree, so all the
                            // search results data will be needed, and this will save reopening the
                            // archive for each file
                            stream.Seek(0, SeekOrigin.Begin);
                            using (StreamReader streamReader = new StreamReader(stream, encoding, false, 4096, true))
                            {
                                foreach (var result in innerFileResults)
                                {
                                    // file info is known, set it now
                                    result.FileInfo = fileData;

                                    if (Utils.CancelSearch)
                                    {
                                        break;
                                    }

                                    result.SearchResults = Utils.GetLinesEx(streamReader, result.Matches, engine.LinesBefore, engine.LinesAfter);
                                }
                            }
                        }
                        else
                        {
                            foreach (var result in innerFileResults)
                            {
                                // file info is known, set it now
                                result.FileInfo = fileData;

                                if (Utils.CancelSearch)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        // short circuit this file
                        innerFileResults = null;
                    }
                    GrepEngineFactory.ReturnToPool(innerFileName, engine);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, string.Format(CultureInfo.CurrentCulture, "Failed to search inside archive '{0}'", innerFileName));
            }

            return(innerFileResults);
        }
        /// <summary>
        /// Process character swaps upon clicking.
        /// </summary>
        private void ButtonDark_Swap_Click(object sender, EventArgs e)
        {
            // Used for storage.
            ArchiveDirectory player = null;

            if (!File.Exists(ArchivePath))
            {
                MarathonMessageBox.Show
                (
                    "The original archive loaded has been removed - unable to decompress contents.",
                    "Missing Archive",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );

                Close();

                return;
            }
#if !DEBUG
            try
            {
#endif
            // Decompress all data.
            LoadedArchive.Decompress(ref LoadedArchive.Data);
#if !DEBUG
        }
        catch
        {
            MarathonMessageBox.Show
            (
                "Failed to decompress 'player.arc' - the archive may be corrupt or invalid.",
                "Archive Error",
                MessageBoxButtons.OK,
                MessageBoxIcon.Error
            );

            Close();

            return;
        }
#endif
            // Check if 'xenon\player\' returns null.
            if ((player = LoadedArchive.JumpToDirectory(@"xenon\player\")) == null)
            {
                // If so, then check if 'ps3\player\' returns null.
                if ((player = LoadedArchive.JumpToDirectory(@"ps3\player\")) == null)
                {
                    MarathonMessageBox.Show
                    (
                        "Failed to locate the scripts directory...",
                        "Archive Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                    );

                    Close();
                }
            }

            for (int i = 0; i < player.TotalContentsCount; i++)
            {
                ArchiveFile script = (ArchiveFile)player.Data[i];

                switch (script.Name.ToLower())
                {
                    /* Due to some backwards decisions from our good friends at Microsoft,
                     * DropDownLists cannot have pre-defined text and I'm not using standard DropDowns for this...
                     *
                     * I did warn you above. */

                    #region Characters
                case "sonic_new.lub":
                    ReplaceScriptData(script, ComboBoxDark_Sonic);
                    break;

                case "shadow.lub":
                    ReplaceScriptData(script, ComboBoxDark_Shadow);
                    break;

                case "silver.lub":
                    ReplaceScriptData(script, ComboBoxDark_Silver);
                    break;

                case "princess.lub":
                    ReplaceScriptData(script, ComboBoxDark_PrincessElise);
                    break;

                case "sonic_fast.lub":
                    ReplaceScriptData(script, ComboBoxDark_SonicMachSpeed);
                    break;

                case "supersonic.lub":
                    ReplaceScriptData(script, ComboBoxDark_SuperSonic);
                    break;

                case "supershadow.lub":
                    ReplaceScriptData(script, ComboBoxDark_SuperShadow);
                    break;

                case "supersilver.lub":
                    ReplaceScriptData(script, ComboBoxDark_SuperSilver);
                    break;

                case "amy.lub":
                    ReplaceScriptData(script, ComboBoxDark_Amy);
                    break;

                case "blaze.lub":
                    ReplaceScriptData(script, ComboBoxDark_Blaze);
                    break;

                case "knuckles.lub":
                    ReplaceScriptData(script, ComboBoxDark_Knuckles);
                    break;

                case "omega.lub":
                    ReplaceScriptData(script, ComboBoxDark_Omega);
                    break;

                case "rouge.lub":
                    ReplaceScriptData(script, ComboBoxDark_Rouge);
                    break;

                case "tails.lub":
                    ReplaceScriptData(script, ComboBoxDark_Tails);
                    break;
                    #endregion

                    #region Vehicles
                case "snow_board.lub":
                    ReplaceScriptData(script, ComboBoxDark_SnowboardCrisisCity);
                    break;

                case "snow_board_wap.lub":
                    ReplaceScriptData(script, ComboBoxDark_SnowboardWhiteAcropolis);
                    break;

                case "shadow_bike.lub":
                    ReplaceScriptData(script, ComboBoxDark_Bike);
                    break;

                case "shadow_glider.lub":
                    ReplaceScriptData(script, ComboBoxDark_Glider);
                    break;

                case "shadow_hover.lub":
                    ReplaceScriptData(script, ComboBoxDark_Hovercraft);
                    break;

                case "shadow_jeep.lub":
                    ReplaceScriptData(script, ComboBoxDark_Jeep);
                    break;

                case "shadow_none.lub":
                    ReplaceScriptData(script, ComboBoxDark_None);
                    break;
                    #endregion

                    #region Bosses
                case "sonic_boss_dr3.lub":
                    ReplaceScriptData(script, ComboBoxDark_EggWyvern);
                    break;

                case "silver_boss_dr2.lub":
                    ReplaceScriptData(script, ComboBoxDark_EggGenesis);
                    break;

                case "silver_boss_iblis1.lub":
                    ReplaceScriptData(script, ComboBoxDark_IblisPhase1);
                    break;

                case "silver_boss_iblis3.lub":
                    ReplaceScriptData(script, ComboBoxDark_IblisPhase3);
                    break;

                case "boss_sonic.lub":
                    ReplaceScriptData(script, ComboBoxDark_SonicBoss);
                    break;

                case "boss_shadow.lub":
                    ReplaceScriptData(script, ComboBoxDark_ShadowBoss);
                    break;

                case "boss_silver.lub":
                    ReplaceScriptData(script, ComboBoxDark_SilverBoss);
                    break;
                    #endregion

                    #region Artificial Intelligence
                case "npc_sonic.lub":
                    ReplaceScriptData(script, ComboBoxDark_SonicNPC);
                    break;

                case "npc_shadow.lub":
                    ReplaceScriptData(script, ComboBoxDark_ShadowNPC);
                    break;

                case "npc_silver.lub":
                    ReplaceScriptData(script, ComboBoxDark_SilverNPC);
                    break;

                case "npc_princess.lub":
                    ReplaceScriptData(script, ComboBoxDark_PrincessEliseNPC);
                    break;

                case "npc_supersonic.lub":
                    ReplaceScriptData(script, ComboBoxDark_SuperSonicNPC);
                    break;

                case "npc_supershadow.lub":
                    ReplaceScriptData(script, ComboBoxDark_SuperShadowNPC);
                    break;

                case "npc_supersilver.lub":
                    ReplaceScriptData(script, ComboBoxDark_SuperSilverNPC);
                    break;

                case "npc_amy.lub":
                    ReplaceScriptData(script, ComboBoxDark_AmyNPC);
                    break;

                case "npc_blaze.lub":
                    ReplaceScriptData(script, ComboBoxDark_BlazeNPC);
                    break;

                case "npc_knuckles.lub":
                    ReplaceScriptData(script, ComboBoxDark_KnucklesNPC);
                    break;

                case "npc_omega.lub":
                    ReplaceScriptData(script, ComboBoxDark_OmegaNPC);
                    break;

                case "npc_rouge.lub":
                    ReplaceScriptData(script, ComboBoxDark_RougeNPC);
                    break;

                case "npc_tails.lub":
                    ReplaceScriptData(script, ComboBoxDark_TailsNPC);
                    break;
                    #endregion

                    #region Character Select
                case "select_sonic.lub":
                    ReplaceScriptData(script, ComboBoxDark_SonicMenu);
                    break;

                case "select_shadow.lub":
                    ReplaceScriptData(script, ComboBoxDark_ShadowMenu);
                    break;

                case "select_silver.lub":
                    ReplaceScriptData(script, ComboBoxDark_SilverMenu);
                    break;

                case "select_amy.lub":
                    ReplaceScriptData(script, ComboBoxDark_AmyMenu);
                    break;

                case "select_blaze.lub":
                    ReplaceScriptData(script, ComboBoxDark_BlazeMenu);
                    break;

                case "select_knuckles.lub":
                    ReplaceScriptData(script, ComboBoxDark_KnucklesMenu);
                    break;

                case "select_omega.lub":
                    ReplaceScriptData(script, ComboBoxDark_OmegaMenu);
                    break;

                case "select_rouge.lub":
                    ReplaceScriptData(script, ComboBoxDark_RougeMenu);
                    break;

                case "select_tails.lub":
                    ReplaceScriptData(script, ComboBoxDark_TailsMenu);
                    break;
                    #endregion
                }
            }

            // Replace script data with the selected one.
            void ReplaceScriptData(ArchiveFile script, ComboBox comboBox)
            {
                // Find script entered into the combo box.
                ArchiveFile scriptToUse = Scripts.Find(x => x.Name == comboBox.Text);

                if (script.Name != scriptToUse.Name)
                {
                    // Create replacement file with the original name and replacement data.
                    var replacement = new U8Archive.U8ArchiveFile(scriptToUse)
                    {
                        Name = script.Name
                    };

                    // Replace the script with the requested replacement.
                    LoadedArchive.ReplaceFile(script, replacement);
                }
            }

            // Write swapped character archive.
            WriteFinalisedArchive();
        }
 public ArchiveFile(
     ArchiveDirectory parent, string name, long length, long compressedLength) : base(parent, name)
 {
     Length           = length;
     CompressedLength = compressedLength;
 }
        public async Task LoadSubStorageIndependentResources()
        {
            #region Local
            TempFolder = new StorageDirectory(new[]
            {
                "Temp"
            });
            if (!await TempFolder.Exists())
            {
                await StorageDirectory.CreateSubFolder(new string[] { }, "Temp");
            }

            AppSettingsFolder = new StorageDirectory(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
            });
            if (!await AppSettingsFolder.Exists())
            {
                await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, AppProfileManager.Instance.AppSubStorageIndependentFolderName);
            }

            FavoriteImagesFolder = new StorageDirectory(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                "image_favorites"
            });
            if (!await FavoriteImagesFolder.Exists())
            {
                await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, "image_favorites");
            }

            UserListsFolder = new StorageDirectory(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                "user_lists"
            });
            if (!await UserListsFolder.Exists())
            {
                await StorageDirectory.CreateSubFolder(new[] { FileStorageManager.LocalFilesFolderName }, "user_lists");
            }

            SharedSettingsFile = new StorageFile(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                FileStorageManager.CommonIncomingFolderName,
                "Settings.xml"
            });
            SharedSettingsFile.AllocateParentFolder();

            AppSettingsFile = new StorageFile(new[]
            {
                FileStorageManager.LocalFilesFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
                "Settings.xml"
            });
            AppSettingsFile.AllocateParentFolder();
            #endregion

            #region Remote
            LauncherTemplatesFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                FileStorageManager.CommonIncomingFolderName,
                "LauncherTemplates"
            });
            await LauncherTemplatesFolder.Download();

            SpecialAppsFolder = new ArchiveDirectory(new[]
            {
                FileStorageManager.IncomingFolderName,
                FileStorageManager.CommonIncomingFolderName,
                "SpecialApps"
            });
            if (await SpecialAppsFolder.Exists(true))
            {
                await SpecialAppsFolder.Download();
            }
            #endregion
        }
Example #25
0
        /// <summary>
        /// CollectingBlobに配置されたファイル群をPrimaryBlobに適切に配置する。
        /// </summary>
        /// <remarks>sd 02-7.BLOBインデックス作成</remarks>
        public void Index()
        {
            _logger.Enter();

            try
            {
                IEnumerable <CollectedFile> collectedFiles;
                try
                {
                    // ファイル一覧を取得する
                    var directory = new ArchiveDirectory()
                    {
                        ContainerName = _settings.CollectingBlobContainerNameCollect
                    };

                    // Sq2.1: ファイルを取得する
                    collectedFiles =
                        _collectingRepository.GetArchiveFiles(directory)
                        .Select(x => new CollectedFile(x, _settings, _timeProvider));
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, nameof(Resources.CO_BLI_BLI_003), new object[] { _settings.CollectingBlobContainerNameCollect });
                    return;
                }

                foreach (CollectedFile collectFile in collectedFiles)
                {
                    IndexStatus status = IndexStatus.Copy;

                    try
                    {
                        // メタデータが想定と異なる場合
                        // file作成時刻が既定年月日以上(一定時間以上処理されないケース)
                        if (!collectFile.IsValid())
                        {
                            // Sq2.2: 異常ファイルの集積コンテナにファイルを保存する
                            _collectingRepository.Copy(collectFile.SourceArchiveFile, collectFile.MakeUnknownFile());

                            // Sq2.3: ファイルを削除する(CollectingBlobのファイルを削除する。)
                            status = IndexStatus.Delete;
                            _collectingRepository.Delete(collectFile.SourceArchiveFile);
                            continue;
                        }

                        // メタデータからfileのコピー先を生成する。
                        var fileOnPrimaryBlob = collectFile.MakeClassifiedFile();

                        // Sq2.4: ファイルを保存する
                        status = IndexStatus.CopyToPrimary;
                        _collectingRepository.CopyToPrimary(collectFile.SourceArchiveFile, fileOnPrimaryBlob);

                        // Sq2.5: ファイル情報を保存する
                        if (!TryAddDtDeviceFile(collectFile, fileOnPrimaryBlob))
                        {
                            // Sq2.6: ファイルを削除する(PrimaryBlobのファイルを削除)
                            TryDeleteFromCoreMain(fileOnPrimaryBlob);
                            continue;
                        }

                        // Sq2.7: ファイルを削除する(ファイルの移動を完了したとしてCollectingBlobのファイルを削除する。)
                        status = IndexStatus.Delete;
                        _collectingRepository.Delete(collectFile.SourceArchiveFile);

                        _logger.Info(nameof(Resources.CO_BLI_BLI_009), new object[] { collectFile.SourceArchiveFile.ContainerName, collectFile.SourceArchiveFile.FilePath });
                    }
                    catch (Exception ex)
                    {
                        switch (status)
                        {
                        case IndexStatus.Delete:
                            _logger.Error(ex, nameof(Resources.CO_BLI_BLI_005), new object[] { collectFile.SourceArchiveFile.ContainerName, collectFile.SourceArchiveFile.FilePath });
                            break;

                        case IndexStatus.CopyToPrimary:
                            _logger.Error(ex, nameof(Resources.CO_BLI_BLI_006), new object[] { collectFile.SourceArchiveFile.ContainerName, collectFile.SourceArchiveFile.FilePath });
                            break;

                        case IndexStatus.Copy:
                        default:
                            _logger.Error(ex, nameof(Resources.CO_BLI_BLI_004), new object[] { collectFile.SourceArchiveFile.ContainerName, collectFile.SourceArchiveFile.FilePath });
                            break;
                        }
                    }
                }
            }
            finally
            {
                _logger.Leave();
            }
        }
        private async Task LoadSubStorageDependentResources()
        {
            await Asa.Common.Core.Configuration.ResourceManager.Instance.LoadSubStorageDependentResources();

            await Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.Download();

            await Asa.Common.Core.Configuration.ResourceManager.Instance.ScheduleSlideTemplatesFolder.Download();

            await Asa.Common.Core.Configuration.ResourceManager.Instance.CalendarSlideTemplatesFolder.Download();

            await Asa.Common.Core.Configuration.ResourceManager.Instance.ArtworkFolder.Download();

            await Asa.Common.Core.Configuration.ResourceManager.Instance.RateCardFolder.Download();

            var folderNameParts = !String.IsNullOrEmpty(AppProfileManager.Instance.SubStorageName)
                ? new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageDependentFolderName,
                AppProfileManager.Instance.SubStorageName,
            }
                : new[]
            {
                FileStorageManager.IncomingFolderName,
                AppProfileManager.Instance.AppSubStorageIndependentFolderName,
            };

            FormStyleConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "style.xml"
            }));
            await FormStyleConfigFile.Download();

            MainAppTitleTextFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "app_brand.txt"
            }));
            if (await MainAppTitleTextFile.Exists(true))
            {
                await MainAppTitleTextFile.Download();
            }

            ConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "app_common_config.xml"
            }));
            if (await ConfigFile.Exists(true))
            {
                await ConfigFile.Download();
            }

            TextResourcesFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "app_text_config.xml"
            }));
            if (await TextResourcesFile.Exists(true))
            {
                await TextResourcesFile.Download();
            }

            AdditionalTextResourcesFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                String.Format("{0}_subtab_names.xml", MediaMetaData.Instance.DataTypeString.ToLower())
            }));
            if (await AdditionalTextResourcesFile.Exists(true))
            {
                await AdditionalTextResourcesFile.Download();
            }

            SyncFormColorConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "sync_color.xml"
            }));
            if (await SyncFormColorConfigFile.Exists(true))
            {
                await SyncFormColorConfigFile.Download();
            }

            SyncFormTextConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "sync_text.xml"
            }));
            if (await SyncFormTextConfigFile.Exists(true))
            {
                await SyncFormTextConfigFile.Download();
            }

            TabsConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                $"{MediaMetaData.Instance.DataTypeString.ToLower()}_tab_names.xml"
            }));
            await TabsConfigFile.Download();

            BrowserConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "eo.xml"
            }));
            await BrowserConfigFile.Download();

            Gallery1ConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "Gallery1.xml"
            }));
            await Gallery1ConfigFile.Download();

            Gallery2ConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "Gallery2.xml"
            }));
            await Gallery2ConfigFile.Download();

            SolutionsConfigFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "solution_templates.xml"
            }));
            await SolutionsConfigFile.Download();

            IdleSettingsFile = new StorageFile(folderNameParts.Merge(new[]
            {
                "AppSettings",
                "autoclose.xml"
            }));
            if (await IdleSettingsFile.Exists(true))
            {
                await IdleSettingsFile.Download();
            }

            ImageResourcesFolder = new ArchiveDirectory(folderNameParts.Merge(new[]
            {
                "Resources"
            }));
            if (await ImageResourcesFolder.Exists(true))
            {
                await ImageResourcesFolder.Download();
            }

            SolutionsDataFolder = new StorageDirectory(folderNameParts.Merge(new[]
            {
                "Solution Templates"
            }));

            MediaListsFile = new StorageFile(
                Asa.Common.Core.Configuration.ResourceManager.Instance.DictionariesFolder.RelativePathParts.Merge(
                    String.Format("{0} Strategy.xml", MediaMetaData.Instance.DataTypeString)));

            #region Make local copy

            if (SyncFormColorConfigFile.ExistsLocal())
            {
                File.Copy(SyncFormColorConfigFile.LocalPath, Path.Combine(Asa.Common.Core.Configuration.ResourceManager.Instance.AppRootFolderPath, Path.GetFileName(SyncFormColorConfigFile.LocalPath)), true);
            }
            if (SyncFormTextConfigFile.ExistsLocal())
            {
                File.Copy(SyncFormTextConfigFile.LocalPath, Path.Combine(Asa.Common.Core.Configuration.ResourceManager.Instance.AppRootFolderPath, Path.GetFileName(SyncFormTextConfigFile.LocalPath)), true);
            }

            #endregion
        }