Ejemplo n.º 1
0
        public void OnApplicationRequestOpenRooms()
        {
            var ofd = new CommonOpenFileDialog()
            {
                Title = "Choose Rooms to Open",
                AddToMostRecentlyUsedList = false,
                AllowNonFileSystemItems   = false,
                EnsureFileExists          = true,
                EnsurePathExists          = true,
                EnsureReadOnly            = false,
                EnsureValidNames          = true,
                Multiselect    = true,
                ShowPlacesList = true
            };

            ofd.Filters.Add(new CommonFileDialogFilter("RARC Archives", ".arc"));
            ofd.Filters.Add(new CommonFileDialogFilter("All Files", ".*"));

            if (WSettingsManager.GetSettings().LastStagePath.FilePath != "")
            {
                ofd.InitialDirectory = WSettingsManager.GetSettings().LastStagePath.FilePath;
            }

            if (ofd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                List <string> files   = new List <string>(ofd.FileNames);
                string        dirPath = Path.GetDirectoryName(files[0]);

                string stageArcPath = Path.Combine(dirPath, "Stage.arc");
                if (!files.Contains(stageArcPath) && File.Exists(stageArcPath))
                {
                    // Always load the stage arc even if it wasn't selected by the user.
                    files.Add(stageArcPath);
                }

                string tempMapPath = Path.Combine(GetStageDumpPath(), Path.GetFileName(dirPath)); // This is where we'll dump the arc contents to

                DeleteDumpContentsFromTempDir();

                if (!Directory.Exists(GetStageDumpPath()))
                {
                    Directory.CreateDirectory(GetStageDumpPath());
                }

                if (!Directory.Exists(tempMapPath))
                {
                    Directory.CreateDirectory(tempMapPath);
                }

                foreach (var arc in files)
                {
                    VirtualFilesystemDirectory archiveRoot = ArchiveUtilities.LoadArchive(arc);
                    if (archiveRoot == null)
                    {
                        continue;
                    }

                    string tempArcPath = $"{tempMapPath}\\{archiveRoot.Name}";

                    if (!Directory.Exists(tempArcPath))
                    {
                        Directory.CreateDirectory(tempMapPath);
                    }

                    DumpContents(archiveRoot, tempArcPath);
                }

                LoadProject(tempMapPath, dirPath);

                // This will signal that we loaded from archives, and that there is no valid path to save the map yet.
                MainWorld.Map.SavePath = null;
                m_sourceDataPath       = tempMapPath;

                WSettingsManager.GetSettings().LastStagePath.FilePath = dirPath;
                WSettingsManager.SaveSettings();
            }
        }
Ejemplo n.º 2
0
        public void OnApplicationRequestOpenProject()
        {
            var ofd = new CommonOpenFileDialog()
            {
                Title                     = "Choose Directory",
                IsFolderPicker            = true,
                AddToMostRecentlyUsedList = false,
                AllowNonFileSystemItems   = false,
                EnsureFileExists          = true,
                EnsurePathExists          = true,
                EnsureReadOnly            = false,
                EnsureValidNames          = true,
                Multiselect               = false,
                ShowPlacesList            = true
            };

            if (WSettingsManager.GetSettings().LastStagePath.FilePath != "")
            {
                ofd.InitialDirectory = WSettingsManager.GetSettings().LastStagePath.FilePath;
            }

            if (ofd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                List <string> files = new List <string>(Directory.GetFiles(ofd.FileName));
                List <string> dirs  = new List <string>(Directory.GetDirectories(ofd.FileName));

                // There are directories here, and one of them is an unpacked Stage folder, so try to load all of these instead of loading the .arcs.
                if (dirs.Count != 0 && File.Exists(Path.Combine(ofd.FileName, "Stage/dzs/stage.dzs")))
                {
                    LoadProject(ofd.FileName, ofd.FileName);
                    m_sourceDataPath = ofd.FileName;
                }
                // We'll have to dump the contents of the arcs
                else
                {
                    string tempMapPath = HandleTempPath(ofd.FileName);

                    foreach (var arc in files)
                    {
                        var   filename = Path.GetFileName(arc);
                        Regex reg      = new Regex(@"(Stage|Room\d+).arc", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        if (!reg.IsMatch(filename))
                        {
                            continue;
                        }

                        VirtualFilesystemDirectory archiveRoot = ArchiveUtilities.LoadArchive(arc);
                        if (archiveRoot == null)
                        {
                            continue;
                        }

                        string tempArcPath = $"{tempMapPath}\\{archiveRoot.Name}";

                        if (!Directory.Exists(tempArcPath))
                        {
                            Directory.CreateDirectory(tempMapPath);
                        }

                        DumpContents(archiveRoot, tempArcPath);
                    }

                    LoadProject(tempMapPath, ofd.FileName);

                    // This will signal that we loaded from archives, and that there is no valid path to save the map yet.
                    MainWorld.Map.SavePath = null;
                    m_sourceDataPath       = tempMapPath;

                    WSettingsManager.GetSettings().LastStagePath.FilePath = ofd.FileName;
                    WSettingsManager.SaveSettings();
                }
            }
        }