private async Task ChangeEncoding(string filePath, string fileOutputPath, EncodingTypes fromEncoding, EncodingTypes toEncoding)
        {
            filePath       = FormatPath(filePath);
            fileOutputPath = FormatPath(fileOutputPath);
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var arabic = Encoding.GetEncoding(1256);

            string contents = await File.ReadAllTextAsync(filePath, arabic);

            if (string.IsNullOrEmpty(contents))
            {
                await Task.CompletedTask;
                return;
            }

            var utf8 = UTF8Encoding.GetEncoding(65001);

            var fileOutputDirectory = new DirectoryInfo(fileOutputPath).Parent.FullName.ToString();

            if (!isDirectoryExist(fileOutputDirectory))
            {
                Directory.CreateDirectory(fileOutputDirectory);
            }

            await File.WriteAllTextAsync(fileOutputPath, contents, utf8);
        }
Exemplo n.º 2
0
        private void SaveSpawnQueries(List <string> files)
        {
            var queries = new List <string>();
            var entry   = DbStartingId;
            var currX   = TopLeftX;
            var currY   = TopLeftY;
            var limitX  = BottomRightX;
            var limitY  = BottomRightY;

            for (var i = 0; i < files.Count; ++i)
            {
                // id, map, zone, x, y, z, health
                queries.Add(string.Format(CreatureQuery, entry++, MapId, 0, currX, currY, CoordZ, 100));
                currX -= CellSize;
                if (currX <= limitX)
                {
                    currX  = TopLeftX;
                    currY -= CellSize;
                    if (currY <= limitY)
                    {
                        throw new Exception("Spawned outside of defined grid.");
                    }
                }
            }
            File.WriteAllLines("Export/Creature.sql", queries, UTF8Encoding.GetEncoding(0));
        }
Exemplo n.º 3
0
        private static void generateSpawnQueries()
        {
            StringBuilder str     = new StringBuilder();
            uint          newSize = (uint)paths.Count + DBCStartingEntry;

            string[] stringPaths   = paths.ToArray();
            uint     creatureEntry = CTStartingEntry;

            int currX  = MapTopLeft[0];
            int currY  = MapTopLeft[1];
            int limitX = MapBottomRight[0];
            int limitY = MapBottomRight[1];

            for (uint i = DBCStartingEntry; i < newSize; ++i)
            {
                str.Append("insert into `creature` (`id`, `map`, `zoneId`, `areaId`, `spawnMask`, `phaseMask`, `modelid`, `equipment_id`," +
                           " `position_x`, `position_y`, `position_z`, `orientation`, `spawntimesecs`, `currentwaypoint`, `curhealth`," +
                           " `curmana`, `MovementType`, `npcflag`, `unit_flags`, `dynamicflags`, `VerifiedBuild`)");
                str.Append(string.Format("values('{0}','{1}','{2}','0','1','1','0','0','{3}','{4}','{5}','0','30','0','{6}','0','0','0','0','0','0');\n",
                                         creatureEntry++, MapEntry, 0, currX, currY, MapZ, 100)); // id, map, zone, x, y, z, health
                currX -= CellSize;
                if (currX <= limitX)
                {
                    currX  = MapTopLeft[0];
                    currY -= CellSize;
                    if (currY <= limitY)
                    {
                        throw new Exception("Spawned outside of defined grid.");
                    }
                }
            }
            File.WriteAllText("Export/Creature.sql", str.ToString(), UTF8Encoding.GetEncoding(0));
        }
Exemplo n.º 4
0
        public static T Load(string inFilePath, string inFileName)
        {
            string sFP = inFilePath + "\\" + inFileName;

            if (!File.Exists(sFP))
            {
                var instance = new T();
                Save(inFilePath, inFileName, instance);
                return(instance);
            }

            //var coder = new UnicodeEncoding(false, true);
            var coder = UTF8Encoding.GetEncoding(1251);

            byte[] buff = null;
            using (FileStream fs = File.Open(sFP, FileMode.Open, FileAccess.Read))
            {
                buff = new byte[fs.Length];
                if (fs.Read(buff, 0, buff.Length) == 0)
                {
                    buff = null;
                }
            }

            if (buff != null)
            {
                string s        = coder.GetString(buff);
                var    instance = JsonConvert.DeserializeObject <T>(s);
                return(instance);
            }

            return(default(T));
        }
Exemplo n.º 5
0
        public Parser()
        {
            var webSite = new HtmlWeb
            {
                AutoDetectEncoding = false,
                OverrideEncoding   = UTF8Encoding.GetEncoding("windows-1251")
            };

            WebGet = webSite;
        }
Exemplo n.º 6
0
        private void SaveTemplateQueries(List <string> files)
        {
            var queries = new List <string>();
            var entry   = DbStartingId;

            for (var i = 0; i < files.Count; ++i)
            {
                var name = files[i].Substring(files[i].IndexOf("SPELL"));
                queries.Add(string.Format(CreatureTemplateQuery, entry, entry, MySqlHelper.EscapeString(name)));
                queries.Add(string.Format(CreatureDisplayInfoQuery, entry));
                ++entry;
            }
            File.WriteAllLines("Export/CreatureTemplate.sql", queries, UTF8Encoding.GetEncoding(0));
        }
Exemplo n.º 7
0
        public static void Save(string inFilePath, string inFileName, T inObject)
        {
            string sFP = inFilePath + "\\" + inFileName;

            string s = JsonConvert.SerializeObject(inObject, Formatting.Indented);

            //var coder = new UnicodeEncoding();
            var coder = UTF8Encoding.GetEncoding(1251);

            Byte[] encodedBytes = coder.GetBytes(s);

            using (FileStream fs = File.Open(sFP, FileMode.Create, FileAccess.Write))
            {
                fs.Write(encodedBytes, 0, encodedBytes.Length);
            }
        }
Exemplo n.º 8
0
        private static string SaveInternal(string s, string path)
        {
            // Do not overwrite if file hasn't changed.
            if (File.Exists(path))
            {
                string old_s = File.ReadAllText(path, UTF8Encoding.GetEncoding(0));
                if (s.Equals(old_s))
                {
                    return(s);
                }
            }

            var bytes = Encoding.UTF8.GetBytes(s);

            File.WriteAllBytes(path, bytes);
            return(s);
        }
Exemplo n.º 9
0
        private static void generateTemplateQueries()
        {
            StringBuilder str     = new StringBuilder();
            uint          newSize = (uint)paths.Count + DBCStartingEntry;

            string[] stringPaths   = paths.ToArray();
            uint     creatureEntry = CTStartingEntry;

            for (uint i = DBCStartingEntry; i < newSize; ++i)
            {
                str.Append("INSERT INTO `creature_template` (entry, modelid1, name, subname, IconName, faction) VALUES (");
                str.Append(string.Format("'{0}', '{1}', \"{2}\", '', '', 35);\n", creatureEntry++, i,
                                         MySqlHelper.EscapeString(stringPaths[i - DBCStartingEntry])));
                str.Append(string.Format("INSERT INTO `creature_model_info` VALUES ('{0}', '0', '0', '0', '0');\n", i));
            }
            File.WriteAllText("Export/CreatureTemplate.sql", str.ToString(), UTF8Encoding.GetEncoding(0));
        }
Exemplo n.º 10
0
        private static void generateTemplateQueries()
        {
            StringBuilder str     = new StringBuilder();
            uint          newSize = (uint)paths.Count + DBCStartingEntry;

            String[] stringPaths   = paths.ToArray();
            uint     creatureEntry = CTStartingEntry;

            for (uint i = DBCStartingEntry; i < newSize; ++i)
            {
                str.Append("INSERT INTO `creature_template` VALUES (");
                str.Append(String.Format("'{0}', '0','0','0','0','0', '{1}', '0','0','0', \"{2}\",", creatureEntry++, i,
                                         MySqlHelper.EscapeString(stringPaths[i - DBCStartingEntry])));
                str.Append("'','','0','1','1','0','35','0','1','1.14286','1','0','0','1500','2000','1','1','1','0','0','0','0'"
                           + ",'0','0','0','0','6','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0',"
                           + "'0','','0','3','1','4','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','','0');\n");
                str.Append(String.Format("INSERT INTO `creature_model_info` VALUES ('{0}', '0', '0', '0', '0');\n", i));
            }
            File.WriteAllText("Export/CreatureTemplate.sql", str.ToString(), UTF8Encoding.GetEncoding(0));
        }
        /// <summary>
        /// Deserialize an Xml File to T object
        /// </summary>
        /// <param name="frozenObjectFileName">Full file path, including name and extension, eg @"C:\Temp\NewFile.xml"</param>
        /// <returns>T instance or default(T)</returns>
        public static T FromXmlFile(string frozenObjectFileName)
        {
            XmlSerializer serializerXml = new XmlSerializer(typeof(T));

            if (System.IO.File.Exists(frozenObjectFileName))
            {
                Encoding utfencoder = UTF8Encoding.GetEncoding("UTF-16", new EncoderReplacementFallback(""), new DecoderReplacementFallback(""));

                var file = File.Open(frozenObjectFileName, FileMode.Open);
                System.IO.TextReader stream = new System.IO.StreamReader(file);

                string tmp = stream.ReadToEnd();
                //tmp = tmp.UnicodeToCharacter();
                TextReader sr = new StringReader(tmp);

                object o = serializerXml.Deserialize(sr);
                stream.Close();
                return((T)o);
            }
            else
            {
                throw new System.IO.FileNotFoundException(frozenObjectFileName + " was not found.");
            }
        }
Exemplo n.º 12
0
 void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
 {
     Logger.Info("ERROR: " + e.Exception.Message);
     File.WriteAllText("error.txt", e.Exception.Message, UTF8Encoding.GetEncoding(0));
     e.Handled = true;
 }