示例#1
0
 private string getAssetExtension(assetLine asset)
 {
     if (asset.type == "image")
     {
         return(".iwi");
     }
     if (asset.type == "csv")
     {
         return(".csv");
     }
     return("");
 }
示例#2
0
        private void openFile(string fileLoc)
        {
            if (!button1.Enabled)
            {
                return;
            }
            button1.Enabled      = false;
            openMenuItem.Enabled = false;
            // Code to read the contents of the text
            if (Path.GetExtension(fileLoc) != ".map")
            {
                MessageBox.Show("File does not have the correct extension for a map file! (*.map required)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (File.Exists(fileLoc))
            {
                //Console.WriteLine(fileLoc);
                string[] directories = fileLoc.Split(Path.DirectorySeparatorChar);

                if (directories.Count() < 2)
                {
                    MessageBox.Show("File is not located in a valid location! Must be within the root of the map_source folder of a valid installation of CoDWaW!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (directories[directories.Count() - 2] != "map_source")
                {
                    MessageBox.Show("File is not located in a valid location! Must be within the root of the map_source folder of a valid installation of CoDWaW!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string rootDir    = Path.GetFullPath(Path.Combine(fileLoc, @"..\..\"));
                string mapName    = Path.GetFileNameWithoutExtension(fileLoc);
                string targetPath = Path.Combine(Directory.GetCurrentDirectory(), mapName);

                //Console.WriteLine(rootDir);

                string mapnameCSV = Path.Combine(rootDir, @"zone_source\english\assetlist\" + mapName + ".csv");

                if (!File.Exists(mapnameCSV))
                {
                    MessageBox.Show("Could not find an assetlist CSV for your map at " + mapnameCSV + ". Make sure you've compiled this map in Launcher!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (Path.GetFileName(fileLoc).Contains("_patch"))
                {
                    MessageBox.Show("It appears you chose the _patch map file for a map instead of the map file for your map! Please choose the correct file.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                mruMenu.AddFile(fileLoc);

                if (!System.IO.Directory.Exists(targetPath))
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                }

                //Copy the map file to export directory
                if (mapCheck.Checked)
                {
                    if (!System.IO.Directory.Exists(targetPath + @"\map_source\"))
                    {
                        System.IO.Directory.CreateDirectory(targetPath + @"\map_source\");
                    }
                    System.IO.File.Copy(fileLoc, mapName + @"\map_source\" + mapName + ".map", true);

                    if (File.Exists(rootDir + @"map_source\" + mapName + "_patch.map"))
                    {
                        System.IO.File.Copy(rootDir + @"map_source\" + mapName + "_patch.map", mapName + @"\map_source\" + mapName + "_patch.map", true);
                    }

                    if (File.Exists(rootDir + @"map_source\" + mapName + "_load.map"))
                    {
                        System.IO.File.Copy(rootDir + @"map_source\" + mapName + "_load.map", mapName + @"\map_source\" + mapName + "_load.map", true);
                    }
                }

                if (prefabsCheck.Checked)
                {
                    if (!System.IO.Directory.Exists(targetPath + @"\map_source\_prefabs"))
                    {
                        System.IO.Directory.CreateDirectory(targetPath + @"\map_source\_prefabs");
                    }

                    foreach (string line in File.ReadLines(fileLoc))
                    {
                        if (line.Contains("_prefabs"))
                        {
                            string prefabPath = line.Remove(0, 9);
                            prefabPath = prefabPath.Trim('"');
                            prefabPath = prefabPath.Replace('/', '\\');

                            if (File.Exists(rootDir + @"map_source\" + prefabPath))
                            {
                                if (!System.IO.Directory.Exists(targetPath + @"\map_source\" + Path.GetDirectoryName(prefabPath)))
                                {
                                    System.IO.Directory.CreateDirectory(targetPath + @"\map_source\" + Path.GetDirectoryName(prefabPath));
                                }

                                System.IO.File.Copy(rootDir + @"map_source\" + prefabPath, mapName + @"\map_source\" + prefabPath, true);
                            }
                        }
                    }
                }

                if (launcherCfg.Checked)
                {
                    if (!System.IO.Directory.Exists(targetPath + @"\bin\Launcher\map_settings"))
                    {
                        System.IO.Directory.CreateDirectory(targetPath + @"\bin\Launcher\map_settings");
                    }

                    if (File.Exists(rootDir + @"\bin\Launcher\map_settings\" + mapName + ".cfg"))
                    {
                        System.IO.File.Copy(rootDir + @"\bin\Launcher\map_settings\" + mapName + ".cfg", mapName + @"\bin\Launcher\map_settings\" + mapName + ".cfg", true);
                    }
                    if (File.Exists(rootDir + @"\bin\Launcher\map_settings\" + mapName + "_load.cfg"))
                    {
                        System.IO.File.Copy(rootDir + @"\bin\Launcher\map_settings\" + mapName + "_load.cfg", mapName + @"\bin\Launcher\map_settings\" + mapName + "_load.cfg", true);
                    }
                    if (File.Exists(rootDir + @"\bin\Launcher\map_settings\" + mapName + "_patch.cfg"))
                    {
                        System.IO.File.Copy(rootDir + @"\bin\Launcher\map_settings\" + mapName + "_patch.cfg", mapName + @"\bin\Launcher\map_settings\" + mapName + "_patch.cfg", true);
                    }
                }

                if (zonesource.Checked)
                {
                    if (!System.IO.Directory.Exists(targetPath + @"\zone_source"))
                    {
                        System.IO.Directory.CreateDirectory(targetPath + @"\zone_source");
                    }

                    if (File.Exists(rootDir + @"\zone_source\" + mapName + ".csv"))
                    {
                        System.IO.File.Copy(rootDir + @"\zone_source\" + mapName + ".csv", mapName + @"\zone_source\" + mapName + ".csv", true);
                    }
                    if (File.Exists(rootDir + @"\zone_source\" + mapName + "_load.csv"))
                    {
                        System.IO.File.Copy(rootDir + @"\zone_source\" + mapName + "_load.csv", mapName + @"\zone_source\" + mapName + "_load.csv", true);
                    }
                    if (File.Exists(rootDir + @"\zone_source\" + mapName + "_patch.csv"))
                    {
                        System.IO.File.Copy(rootDir + @"\zone_source\" + mapName + "_patch.csv", mapName + @"\zone_source\" + mapName + "_patch.csv", true);
                    }
                }

                foreach (var line in File.ReadLines(mapnameCSV))
                {
                    var       values = line.Split(',');
                    assetLine asset  = new assetLine();
                    asset.type = Convert.ToString(values[0]);
                    asset.name = Convert.ToString(values[1]);

                    if (imagesCheck.Checked && asset.type == "image")
                    {
                        string imagePath = Path.Combine(rootDir, @"raw\images\" + asset.name + ".iwi");

                        if (!System.IO.Directory.Exists(targetPath + @"\raw\images\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\raw\images\");
                        }

                        if (!System.IO.Directory.Exists(targetPath + @"\mods\" + mapName + @"\images\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\mods\" + mapName + @"\images\");
                        }

                        if (File.Exists(imagePath) && !isFileTooOld(imagePath))
                        {
                            System.IO.File.Copy(imagePath, mapName + @"\raw\images\" + asset.name + ".iwi", true);
                            System.IO.File.Copy(imagePath, mapName + @"\mods\" + mapName + @"\images\" + asset.name + ".iwi", true);
                        }
                        //Console.WriteLine(imagePath);
                    }
                    if (materialsCheck.Checked && asset.type == "material")
                    {
                        string[] split = asset.name.Split('/');
                        string   name  = asset.name;
                        if (split.Count() > 1)
                        {
                            name = split[split.Count() - 1];
                        }

                        if (name.Contains('*')) //invalid path character
                        {
                            continue;
                        }

                        string materialPath     = Path.Combine(rootDir, @"raw\materials\" + name);
                        string materialPropPath = Path.Combine(rootDir, @"raw\material_properties\" + name);

                        if (!System.IO.Directory.Exists(targetPath + @"\raw\materials\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\raw\materials\");
                        }
                        if (!System.IO.Directory.Exists(targetPath + @"\raw\material_properties\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\raw\material_properties\");
                        }

                        if (File.Exists(materialPath) && !isFileTooOld(materialPath))
                        {
                            System.IO.File.Copy(materialPath, mapName + @"\raw\materials\" + name, true);
                        }
                        if (File.Exists(materialPropPath) && !isFileTooOld(materialPropPath))
                        {
                            System.IO.File.Copy(materialPropPath, mapName + @"\raw\material_properties\" + name, true);
                        }
                        //Console.WriteLine(materialPath);
                    }
                    if (xmodelsCheck.Checked && asset.type == "xmodel")
                    {
                        string xmodelPath = Path.Combine(rootDir, @"raw\xmodel\" + asset.name);
                        //Console.WriteLine(xmodelPath);

                        if (!System.IO.Directory.Exists(targetPath + @"\raw\xmodel\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\raw\xmodel\");
                        }
                        if (!System.IO.Directory.Exists(targetPath + @"\raw\xmodelsurfs\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\raw\xmodelsurfs\");
                        }
                        if (!System.IO.Directory.Exists(targetPath + @"\raw\xmodelparts\"))
                        {
                            System.IO.Directory.CreateDirectory(targetPath + @"\raw\xmodelparts\");
                        }

                        if (File.Exists(xmodelPath) && !isFileTooOld(xmodelPath))
                        {
                            System.IO.File.Copy(xmodelPath, mapName + @"\raw\xmodel\" + asset.name, true);
                        }
                        else
                        {
                            continue;                                                 //dont bother looking for the rest if the xmodel wasn't found or is too old
                        }
                        List <string> xmodelstuff = getStringsFromXmodel(xmodelPath); //all of the texture filenames associated with this material
                        if (xmodelstuff != null)
                        {
                            foreach (string stuff in xmodelstuff)
                            {
                                string xmodelSurf = Path.Combine(rootDir, @"raw\xmodelsurfs\" + stuff);
                                if (File.Exists(xmodelSurf))
                                {
                                    System.IO.File.Copy(xmodelSurf, mapName + @"\raw\xmodelsurfs\" + stuff, true);
                                    //Console.WriteLine(xmodelSurf);
                                }

                                string xmodelPart = Path.Combine(rootDir, @"raw\xmodelparts\" + stuff);
                                if (File.Exists(xmodelPart))
                                {
                                    System.IO.File.Copy(xmodelPart, mapName + @"\raw\xmodelparts\" + stuff, true);
                                    //Console.WriteLine(xmodelPart);
                                }
                            }
                        }
                    }

                    _assets.Add(asset);
                }

                if (zipCheck.Checked)
                {
                    if (File.Exists(mapName + ".zip"))
                    {
                        File.Delete(mapName + ".zip");
                    }
                    System.IO.Compression.ZipFile.CreateFromDirectory(targetPath, mapName + ".zip", CompressionLevel.Fastest, true);
                    Directory.Delete(targetPath, true);
                }
                MessageBox.Show(mapName + " exported sucessfully to current program directory.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("File could not be opened (unknown error)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            currentlyBusy        = false;
            button1.Enabled      = true;
            openMenuItem.Enabled = true;
        }