private void Button_Click(object sender, RoutedEventArgs e)
        {
            var parameters = new CompilerParameters()
            {
                GenerateInMemory = true
            };

            parameters.ReferencedAssemblies.Add("System.Xml.dll");
            parameters.ReferencedAssemblies.Add("System.dll");
            parameters.ReferencedAssemblies.Add("XmlClasses.dll");
            parameters.ReferencedAssemblies.Add("System.Linq.dll");
            var results = provider.CompileAssemblyFromSource(parameters, codeBox.Text);

            if (results.Errors.HasErrors)
            {
                string error = "";
                foreach (CompilerError err in results.Errors)
                {
                    error += err.ErrorText + "\n";
                }
                MessageBox.Show(error);
                return;
            }
            Type       Script = results.CompiledAssembly.GetType("Scripts.Script");
            MethodInfo Run    = Script.GetMethod("Run");

            File = (XmlStrings)Run.Invoke(null, new object[] { File });
        }
 public ScriptWindow(ref XmlStrings file)
 {
     InitializeComponent();
     File         = file;
     provider     = new CSharpCodeProvider();
     codeBox.Text = defaultCode;
 }
Esempio n. 3
0
 private void getFileFromScratch()
 {
     if (System.IO.File.Exists(fileScratchPath))
     {
         loadedFile = readXmlString(System.IO.File.ReadAllText(fileScratchPath));
     }
     else
     {
         throw new Exception("Failed to load file");
     }
 }
Esempio n. 4
0
        private static string SerializeXmlToString(XmlStrings xmls)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(XmlStrings));

            using (TextWriter tw = new StringWriter())
            {
                serializer.Serialize(tw, xmls);
                string result = tw.ToString();
                //result = Utf16ToUtf8(result);
                return(result.Replace("utf-16", "utf-8"));
            }
        }
Esempio n. 5
0
 private void loadFile()
 {
     loadedFile = readXmlString(System.IO.File.ReadAllText(loadDirectory));
     fileIsOpen = true;
     currentStringsList.Clear();
     foreach (XmlString s in loadedFile.Strings)
     {
         s.Description = getDescription(s.Key);
         //currentStringsList.Add(s);
     }
     currentStringsList        = loadedFile.Strings;
     listItemsView.ItemsSource = currentStringsList;
     updateStatus();
 }
Esempio n. 6
0
        private void newFile()
        {
            MessageBoxResult result = MessageBox.Show(
                "Use the english file as a blueprint?", "New File", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                loadedFile = new XmlStrings();
                try
                {
                    getFileFromScratch();
                }
                catch
                {
                    MessageBox.Show("Failed to load blueprint, connect to the internet and restart.");
                }
                currentStringsList.Clear();
                foreach (XmlString s in loadedFile.Strings)
                {
                    s.Description = getDescription(s.Key);
                }
                currentStringsList = loadedFile.Strings;
            }
            fileIsOpen     = true;
            textHasChanged = true;
            LanguagePropertyDialog lpd = new LanguagePropertyDialog(firstTime: true);

            if (lpd.ShowDialog() == true)
            {
                loadedFile.Language.Base    = lpd.LanguageBase;
                loadedFile.Language.Name    = lpd.LanguageName;
                loadedFile.Language.Owner   = lpd.LanguageOwner;
                loadedFile.Language.Variant = lpd.LanguageVariant;
            }
            listItemsView.ItemsSource = currentStringsList;
            updateStatus();
        }
 public ScriptWindow(double height, ref XmlStrings file) : this(ref file)
 {
     Height = height;
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            string path = Ask("Enter path of file to randomize:");

            if (!File.Exists(path))
            {
                Write("File doesn't exist");
                return;
            }
            string     fileString = File.ReadAllText(path);
            XmlStrings file       = ReadXmlString(fileString);
            XmlStrings newFile    = new XmlStrings()
            {
                Language = file.Language
            };
            Regex regex  = new Regex(@"[^\@]\b(\w)+\b");
            Regex number = new Regex(@"\d+");

            foreach (XmlString str in file.Strings)
            {
                XmlString newStr = new XmlString()
                {
                    Isgif = str.Isgif,
                    Key   = str.Key
                };
                foreach (string value in str.Values)
                {
                    Dictionary <string, string> replace = new Dictionary <string, string>();
                    foreach (var m in regex.Matches(value.Replace("\\n", "\n")))
                    {
                        string match = m.ToString();
                        if (number.IsMatch(match) || match.Length < 3)
                        {
                            continue;
                        }
                        Random rnd           = new Random();
                        string first         = match.Substring(0, 1);
                        string last          = match.Substring(match.Length - 1);
                        string proc          = match.Substring(1, match.Length - 2);
                        string output        = first;
                        char[] chars         = new char[proc.Length];
                        var    randomNumbers = Enumerable.Range(0, proc.Length).OrderBy(x => rnd.Next()).Take(proc.Length).ToList();
                        for (int i = 0; i < proc.Length; i++)
                        {
                            chars[i] = proc[randomNumbers[i]];
                        }
                        foreach (var c in chars)
                        {
                            output += c;
                        }
                        output += last;
                        if (!replace.ContainsKey(match))
                        {
                            replace.Add(match, output);
                        }
                    }
                    string newValue = value.Replace("\\n", "\n");
                    foreach (var kvp in replace)
                    {
                        newValue = newValue.Replace(kvp.Key, kvp.Value);
                    }
                    newStr.Values.Add(newValue.Replace("\n", "\\n"));
                }
                newFile.Strings.Add(newStr);
            }
            string finalString = SerializeXmlToString(newFile);

            Write(finalString);
            string toPath = Ask("Path to write file to:");

            File.WriteAllText(toPath, finalString);
            Write("Done.");
            Ask("");
        }