예제 #1
0
        private void UnprotectMapFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title  = "Locate map to unprotect";
            openFileDialog1.Filter = "Starcraft 2 Map (*.SC2Map,*.s2ma,*.mpq)|*.SC2Map;*.s2ma;*.mpq|All files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Safety checks
                MapProtection mapProtection = new MapProtection();
                if (!mapProtection.IsMapProtected(openFileDialog1.FileName))
                {
                    MessageBox.Show("Map is not protected.", "Cannot Unprotect", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return;
                }
                if (Path.GetExtension(openFileDialog1.FileName) == ".s2ma")
                {
                    DialogResult result = MessageBox.Show(
                        "Changing Starcraft II cache files can corrupt your cache.\nAre you sure you want to continue?",
                        "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (result != DialogResult.Yes)
                    {
                        return;
                    }
                }

                //Unprotect the map
                mapProtection.UnprotectMap(openFileDialog1.FileName);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns a list of all SCII maps found on the system (in the cache).
        /// Removed duplicates (only the latest version of a map is returned) based on the map's name
        /// Note that BankInfoCache.InitializeCache() MUST be called before this method!!
        /// </summary>
        public IEnumerable <MapInfo> GetMaps()
        {
            MapProtection mapProtection          = new MapProtection();
            SortedList <string, MapInfo> mapList = new SortedList <string, MapInfo>();
            DirectoryInfo cacheFolder            = new DirectoryInfo(CACHE_FOLDER);

            if (!cacheFolder.Exists)
            {
                return(mapList.Values);
            }

            IEnumerable <FileInfo> mapFiles = cacheFolder.GetFiles("*.s2ma", SearchOption.AllDirectories);
            int numMapFiles      = mapFiles.Count();
            int numMapsProcessed = 0;

            //Load the maps in parallel!
            Parallel.ForEach(mapFiles,
                             //Initialization
                             () => new SortedList <string, MapInfo>(),

                             //Loop body
                             (file, loopState, mapListThread) =>
            {
                string galaxyScriptCode = GetGalaxyScriptCode(file);
                MapInfo mapInfo         = GetMapInfo(file, galaxyScriptCode);
                if (mapInfo != null)
                {
                    bool mapAdded = CheckForDuplicatesAndAdd(mapInfo, mapListThread);
                    if (mapAdded)
                    {
                        //Only do other expensive stuff if map was not a duplicate
                        mapInfo.IsProtected = mapProtection.IsMapProtected(file.FullName);

                        //Use the galaxyscript-code we already loaded to find the bank-names
                        //(See GetBanksFromCode() for more info)
                        mapInfo.BankInfos = _bankInfoLoader.GetBanksFromCode(galaxyScriptCode);
                    }
                }
                Interlocked.Increment(ref numMapsProcessed);
                OnProgressChanged((double)numMapsProcessed / numMapFiles);
                return(mapListThread);
            },

                             //Finalization
                             mapListThread =>
            {
                lock (mapList)
                {
                    foreach (var key in mapListThread.Keys)
                    {
                        CheckForDuplicatesAndAdd(mapListThread[key], mapList);
                    }
                }
            }
                             );

            return(mapList.Values);
        }
예제 #3
0
 private void CopyMap(string oldLocation, string newLocation, bool unprotectMap = true)
 {
     File.Copy(oldLocation, newLocation, true);
     if (unprotectMap)
     {
         MapProtection mapProtection = new MapProtection();
         mapProtection.UnprotectMap(newLocation);
     }
 }