示例#1
0
        public void PreloadModels()
        {
            var path  = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("Data", "Models"));
            var files = new DirectoryInfo(path).GetFiles("*.ini", SearchOption.AllDirectories).ToList();

            for (var i = 0; i < files.Count; i++)
            {
                var modelInfo    = new Ini.IniFile(files[i].FullName);
                var transforms   = new List <Matrix4>();
                var name         = modelInfo.IniReadValue("Global", "Name");
                var num_Pos      = modelInfo.IniReadValue("Global", "Positions");
                var numPositions = int.Parse(num_Pos);

                for (var iP = 0; iP < numPositions; iP++)
                {
                    var positionParts = Functions.SplitString(modelInfo.IniReadValue("Positions", string.Format("Position{0}", iP)), ";");
                    var transform     = Functions.CreateTransformationMatrix(
                        new Vector3(
                            float.Parse(positionParts[0], CultureInfo.InvariantCulture.NumberFormat),
                            float.Parse(positionParts[1], CultureInfo.InvariantCulture.NumberFormat),
                            float.Parse(positionParts[2], CultureInfo.InvariantCulture.NumberFormat)),
                        new Vector3(0.0f),
                        new Vector3(0.01f)
                        );

                    transforms.Add(transform);
                }

                Models.Add(new Models.OBJLoader(name), transforms);
            }
        }
 /// <summary>
 /// 读取地图信息
 /// </summary>
 public void Init_ReadMapInfo()
 {
     try
     {
         #region 读取地图文件信息
         Ini.IniFile ini = new Ini.IniFile(strMapFileIni);
         dblMapInitLon   = double.Parse(ini.IniReadValue("地图信息", "地图初始经度"));
         dblMapInitLat   = double.Parse(ini.IniReadValue("地图信息", "地图初始纬度"));
         intMapInitLevel = int.Parse(ini.IniReadValue("地图信息", "地图初始显示级数"));
         dblMapMinLon    = double.Parse(ini.IniReadValue("地图信息", "最小经度"));
         dblMapMaxLon    = double.Parse(ini.IniReadValue("地图信息", "最大经度"));
         dblMapMinLat    = double.Parse(ini.IniReadValue("地图信息", "最小纬度"));
         dblMapMaxLat    = double.Parse(ini.IniReadValue("地图信息", "最大纬度"));
         intMapMinLevel  = Int32.Parse(ini.IniReadValue("地图信息", "显示最小级数"));
         intMapMaxLevel  = Int32.Parse(ini.IniReadValue("地图信息", "显示最大级数"));
         #endregion
         //地图中心点位置
         pointCurrentMapCenter = new PointD(dblMapInitLon, dblMapInitLat);
         //地图显示等级
         CurrentMapLevel = intMapInitLevel;
     }
     catch (Exception ex)
     {
         Error(ex, "Init_ReadMapInfo");
     }
 }
示例#3
0
        private void LoadDebugConfig()
        {
            Ini.IniFile debug_ini = new Ini.IniFile("./debug.ini");

            string[]   allowed_areas_sno_id_str = debug_ini.IniReadValue("Navmesh", "allowed_areas_sno_id").Split(',');
            List <int> allowed_areas_sno_id     = new List <int>();

            foreach (string id in allowed_areas_sno_id_str)
            {
                if (id.Length > 0)
                {
                    allowed_areas_sno_id.Add(int.Parse(id));
                }
            }
            m_Navmesh.AllowedAreasSnoId = allowed_areas_sno_id;

            string[]   allowed_grid_cells_id_str = debug_ini.IniReadValue("Navmesh", "allowed_grid_cells_id").Split(',');
            List <int> allowed_grid_cells_id     = new List <int>();

            foreach (string id in allowed_grid_cells_id_str)
            {
                if (id.Length > 0)
                {
                    allowed_grid_cells_id.Add(int.Parse(id));
                }
            }
            m_Navmesh.AllowedGridCellsId = allowed_grid_cells_id;

            m_Navmesh.Navigator.UpdatePathInterval = int.Parse(debug_ini.IniReadValue("Navigator", "update_path_interval"));
            m_Navmesh.Navigator.MovementFlags      = (MovementFlag)Enum.Parse(typeof(MovementFlag), debug_ini.IniReadValue("Navigator", "movement_flags"));
            m_Navmesh.Navigator.PathNodesShiftDist = float.Parse(debug_ini.IniReadValue("Navigator", "path_nodes_shift_dist"));
        }
示例#4
0
        private void LoadDebugConfig()
        {
            Ini.IniFile debug_ini = new Ini.IniFile("./debug.ini");

            string[] allowed_areas_sno_id_str = debug_ini.IniReadValue("Navmesh", "allowed_areas_sno_id").Split(',');
            List<int> allowed_areas_sno_id = new List<int>();
            foreach (string id in allowed_areas_sno_id_str)
            {
                if (id.Length > 0)
                    allowed_areas_sno_id.Add(int.Parse(id));
            }
            m_Navmesh.AllowedAreasSnoId = allowed_areas_sno_id;

            string[] allowed_grid_cells_id_str = debug_ini.IniReadValue("Navmesh", "allowed_grid_cells_id").Split(',');
            List<int> allowed_grid_cells_id = new List<int>();
            foreach (string id in allowed_grid_cells_id_str)
            {
                if (id.Length > 0)
                    allowed_grid_cells_id.Add(int.Parse(id));
            }
            m_Navmesh.AllowedGridCellsId = allowed_grid_cells_id;

            m_Navmesh.Navigator.UpdatePathInterval = int.Parse(debug_ini.IniReadValue("Navigator", "update_path_interval"));
            m_Navmesh.Navigator.MovementFlags = (MovementFlag)Enum.Parse(typeof(MovementFlag), debug_ini.IniReadValue("Navigator", "movement_flags"));
            m_Navmesh.Navigator.PathNodesShiftDist = float.Parse(debug_ini.IniReadValue("Navigator", "path_nodes_shift_dist"));
            
        }
示例#5
0
        static void Main()
        {
            ThreadLock = new object();
            Config     = new Ini.IniFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini"));
            Find_Nat_Namespace();
            //Build NativeFiles from Directory if file exists, if not use the files in the resources
            string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                       "natives.dat");

            if (File.Exists(path))
            {
                nativefile = new NativeFile(File.OpenRead(path));
            }
            else
            {
                nativefile = new NativeFile(new MemoryStream(Properties.Resources.natives));
            }


            path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                "x64natives.dat");
            if (File.Exists(path))
            {
                x64nativefile = new x64NativeFile(File.OpenRead(path));
            }
            else
            {
                x64nativefile = new x64NativeFile(new MemoryStream(Properties.Resources.x64natives));
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
示例#6
0
        protected virtual void LoadDebugConfig()
        {
            Ini.IniFile debug_ini = new Ini.IniFile("./debug.ini");

            m_Navigator.UpdatePathInterval = int.Parse(debug_ini.IniReadValue("Navigator", "update_path_interval"));
            m_Navigator.MovementFlags      = (MovementFlag)Enum.Parse(typeof(MovementFlag), debug_ini.IniReadValue("Navigator", "movement_flags"));
            m_Navigator.PathNodesShiftDist = float.Parse(debug_ini.IniReadValue("Navigator", "path_nodes_shift_dist"));
        }
示例#7
0
        //Textbox 1 Change
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (!loaded)
            {
                return;
            }
            var a = new Ini.IniFile(RubyCore.SelfPath + @"\settings.ini");

            a.IniWriteValue("Graphics", "path", textBox1.Text);
        }
示例#8
0
        private void frmComPortSettings_Load(object sender, EventArgs e)
        {
            lbCurrentPorts.DataSource = System.IO.Ports.SerialPort.GetPortNames();

            Ini.IniFile ini = new Ini.IniFile();
            cbComPorts.Text  = ini.IniReadValue("ComportSettings", "COMPort");
            cbBaudRates.Text = ini.IniReadValue("ComportSettings", "BaudRate");
            cbParities.Text  = ini.IniReadValue("ComportSettings", "Parity");
            cbDataBits.Text  = ini.IniReadValue("ComportSettings", "DataBits");
            cbStopBits.Text  = ini.IniReadValue("ComportSettings", "StopBits");
        }
示例#9
0
        protected virtual void LoadDebugConfig()
        {
            if (!File.Exists(DEBUG_CONFIG_FILE))
            {
                return;
            }

            Ini.IniFile debug_ini = new Ini.IniFile(DEBUG_CONFIG_FILE);

            m_Navigator.UpdatePathInterval = int.Parse(debug_ini.IniReadValue("Navigator", "update_path_interval"));
            m_Navigator.MovementFlags      = (MovementFlag)Enum.Parse(typeof(MovementFlag), debug_ini.IniReadValue("Navigator", "movement_flags"));
            m_Navigator.PathNodesShiftDist = float.Parse(debug_ini.IniReadValue("Navigator", "path_nodes_shift_dist"));
        }
示例#10
0
 //Form Load
 private void LoadForm_Load(object sender, EventArgs e)
 {
     if (System.IO.File.Exists(RubyCore.SelfPath + @"\settings.ini"))
     {
         var a = new Ini.IniFile(RubyCore.SelfPath + @"\settings.ini");
         textBox1.Text = a.IniReadValue("Graphics", "path");
         recent_file   = a.IniReadValue("Recent", "path");
         if (File.Exists(recent_file))
         {
             button3.Enabled = true;
         }
     }
     loaded = true;
 }
示例#11
0
        private void LoadMap(string path)
        {
            Core.MapPath      = path;
            Core.GraphicsPath = textBox1.Text;
            Core.LoadMap();
            MainForm main_form = new MainForm(this);

            main_form.Show();
            this.Hide();
            //Recent File
            recent_file     = path;
            button3.Enabled = true;
            var a = new Ini.IniFile(RubyCore.SelfPath + @"\settings.ini");

            a.IniWriteValue("Recent", "path", recent_file);
        }
示例#12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.ComPort  = cbComPorts.Text;
            this.BaudRate = Convert.ToInt32(cbBaudRates.Text);
            this.Parity   = cbParities.Text;
            this.DataBits = Convert.ToByte(cbDataBits.Text);
            this.StopBits = cbStopBits.Text;

            Ini.IniFile ini = new Ini.IniFile();
            ini.IniWriteValue("ComportSettings", "COMPort", this.ComPort);
            ini.IniWriteValue("ComportSettings", "BaudRate", this.BaudRate.ToString());
            ini.IniWriteValue("ComportSettings", "Parity", this.Parity);
            ini.IniWriteValue("ComportSettings", "DataBits", this.DataBits.ToString());
            ini.IniWriteValue("ComportSettings", "StopBits", this.StopBits.ToString());

            this.DialogResult = DialogResult.OK;
        }
示例#13
0
        //Private Methods

        private string get_initial_dir()
        {
            string str = "";

            if (System.IO.File.Exists(RubyCore.SelfPath + @"\settings.ini"))
            {
                var a = new Ini.IniFile(RubyCore.SelfPath + "/settings.ini");
                str = a.IniReadValue("InitFolder", "path");
            }
            if (str == "")
            {
                return(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            }
            else
            {
                return(str);
            }
        }
示例#14
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
            Application.ThreadException += new ThreadExceptionEventHandler(OnFormsUnhandledException);

            try
            {
                Ini.IniFile file = new Ini.IniFile(MainWindow.settings_path);
                if (file.Exists())
                {
                    file.Load();
                    try
                    {
                        if (bool.Parse(file["OptionsUpdates"]["chkAutoUpdate"]))
                        {
                            if (CheckUpdates())
                            {
                                return;
                            }
                        }
                    }
                    catch
                    {
                        if (CheckUpdates())
                        {
                            return;
                        }
                    }
                }

                if (!DirectX_HUDs.AeroEnabled)
                {
                    MessageBox.Show("Desktop Window Manager (DWM) is not enabled. Without DWM, the DirectX overlays used by this program will have a significant performance penalty and may not work properly.\n\nDWM is only available on Windows Vista and later, and requires the Aero theme.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                runApplication();
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception exception)
            {
                WT.ReportCrash(exception, ApplicationTitle + " " + ApplicationVersion);
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            var ini = new Ini.IniFile(@"C:\twitter.ini");

            // Set up your credentials
            Auth.SetCredentials(new TwitterCredentials
            {
                AccessToken       = ini.IniReadValue("Config", "Access_Token"),
                AccessTokenSecret = ini.IniReadValue("Config", "Access_Secret"),
                ConsumerKey       = ini.IniReadValue("Config", "Consumer_Key"),
                ConsumerSecret    = ini.IniReadValue("Config", "Consumer_Secret")
            });

            var stream = Tweetinvi.Stream.CreateSampleStream();

            stream.TweetReceived += (sender, a) =>
            {
                var tp = new TweetProcessor(a.Tweet);

                tp.Process();
            };
            stream.StartStream();
        }
示例#16
0
        protected override void LoadDebugConfig()
        {
            base.LoadDebugConfig();

            Nav.D3.Navmesh navmesh_d3 = (m_Navmesh as Nav.D3.Navmesh);

            if (navmesh_d3 == null)
            {
                return;
            }

            Ini.IniFile debug_ini = new Ini.IniFile("./debug.ini");

            string[]   allowed_areas_sno_id_str = debug_ini.IniReadValue("Navmesh", "allowed_areas_sno_id").Split(',');
            List <int> allowed_areas_sno_id     = new List <int>();

            foreach (string id in allowed_areas_sno_id_str)
            {
                if (id.Length > 0)
                {
                    allowed_areas_sno_id.Add(int.Parse(id));
                }
            }
            navmesh_d3.AllowedAreasSnoId = allowed_areas_sno_id;

            string[]   allowed_grid_cells_id_str = debug_ini.IniReadValue("Navmesh", "allowed_grid_cells_id").Split(',');
            List <int> allowed_grid_cells_id     = new List <int>();

            foreach (string id in allowed_grid_cells_id_str)
            {
                if (id.Length > 0)
                {
                    allowed_grid_cells_id.Add(int.Parse(id));
                }
            }
            navmesh_d3.AllowedGridCellsId = allowed_grid_cells_id;
        }
示例#17
0
        protected virtual void LoadDebugConfig()
        {
            if (!File.Exists(DEBUG_CONFIG_FILE))
            {
                return;
            }

            Ini.IniFile debug_ini = new Ini.IniFile(DEBUG_CONFIG_FILE);

            m_Navigator.UpdatePathInterval            = int.Parse(debug_ini.IniReadValue("Navigator", "update_path_interval"));
            m_Navigator.MovementFlags                 = (MovementFlag)Enum.Parse(typeof(MovementFlag), debug_ini.IniReadValue("Navigator", "movement_flags"));
            m_Navigator.PathNodesShiftDist            = float.Parse(debug_ini.IniReadValue("Navigator", "path_nodes_shift_dist"));
            m_Navigator.DefaultPrecision              = float.Parse(debug_ini.IniReadValue("Navigator", "default_precision"));
            m_Navigator.GridDestPrecision             = float.Parse(debug_ini.IniReadValue("Navigator", "grid_dest_precision"));
            m_Navigator.PathSmoothingPrecision        = float.Parse(debug_ini.IniReadValue("Navigator", "path_smoothing_precision"));
            m_Navigator.KeepFromEdgePrecision         = float.Parse(debug_ini.IniReadValue("Navigator", "keep_from_edge_precision"));
            m_Navigator.CurrentPosDiffRecalcThreshold = float.Parse(debug_ini.IniReadValue("Navigator", "current_pos_diff_recalc_threshold"));

            m_Explorer.ChangeExploreCellSize(int.Parse(debug_ini.IniReadValue("Explorer", "explore_cell_size")));
            m_Explorer.Enabled = bool.Parse(debug_ini.IniReadValue("Explorer", "enabled"));
            m_Explorer.ExploreDestPrecision = float.Parse(debug_ini.IniReadValue("Explorer", "explore_dest_precision"));

            m_BotSpeed = float.Parse(debug_ini.IniReadValue("Bot", "speed"));
        }
示例#18
0
        static void Main(string[] args)
        {
            ThreadLock = new object();
            Config     = new Ini.IniFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini"));
            if (!File.Exists(Config.path))
            {
                Config.IniWriteValue("Base", "IntStyle", "int");
                Config.IniWriteBool("Base", "Show_Array_Size", true);
                Config.IniWriteBool("Base", "Reverse_Hashes", true);
                Config.IniWriteBool("Base", "Declare_Variables", true);
                Config.IniWriteBool("Base", "Shift_Variables", true);
                Config.IniWriteBool("View", "Show_Nat_Namespace", true);
                Config.IniWriteBool("Base", "Show_Func_Pointer", false);
                Config.IniWriteBool("Base", "Use_MultiThreading", false);
                Config.IniWriteBool("Base", "Include_Function_Position", false);
                Config.IniWriteBool("Base", "Uppercase_Natives", false);
                Config.IniWriteBool("Base", "Hex_Index", false);
                Config.IniWriteBool("View", "Line_Numbers", true);
            }
            Find_Show_Array_Size();
            Find_Reverse_Hashes();
            Find_Declare_Variables();
            Find_Shift_Variables();
            Find_Show_Func_Pointer();
            Find_Use_MultiThreading();
            Find_IncFuncPos();
            Find_Nat_Namespace();
            Find_Hex_Index();
            Find_Upper_Natives();
            //Build NativeFiles from Directory if file exists, if not use the files in the resources
            string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                       "natives.dat");

            if (File.Exists(path))
            {
                nativefile = new NativeFile(File.OpenRead(path));
            }
            else
            {
                nativefile = new NativeFile(new MemoryStream(Properties.Resources.natives));
            }


            path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                "x64natives.dat");
            if (File.Exists(path))
            {
                x64nativefile = new x64NativeFile(File.OpenRead(path));
            }
            else
            {
                x64nativefile = new x64NativeFile(new MemoryStream(Properties.Resources.x64natives));
            }

            ScriptFile.npi      = new NativeParamInfo();
            ScriptFile.hashbank = new Hashes();

            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            else
            {
                DateTime Start = DateTime.Now;
                string   ext   = Path.GetExtension(args[0]);
                if (ext == ".full")                 //handle openIV exporting pc scripts as *.ysc.full
                {
                    ext = Path.GetExtension(Path.GetFileNameWithoutExtension(args[0]));
                }
                ScriptFile fileopen;
                Console.WriteLine("Decompiling " + args[0] + "...");
                try
                {
                    fileopen = new ScriptFile(File.OpenRead(args[0]), ext != ".ysc");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error decompiling script " + ex.Message);
                    return;
                }
                Console.WriteLine("Decompiled in " + (DateTime.Now - Start).ToString());
                fileopen.Save(File.OpenWrite(args[0] + ".c"), true);
                Console.WriteLine("Extracing native table...");
                StreamWriter fw = new StreamWriter(File.OpenWrite(args[0] + " native table.txt"));
                foreach (ulong nat in fileopen.X64NativeTable._nativehash)
                {
                    string temps = nat.ToString("X");
                    while (temps.Length < 16)
                    {
                        temps = "0" + temps;
                    }
                    fw.WriteLine(temps);
                }
                fw.Flush();
                fw.Close();
                Console.WriteLine("All done & saved!");
            }
        }
示例#19
0
        public void createCalendar(Ini.IniFile ini, List <Classroom> classrooms, PAZController controller)
        {
            _controller = controller;
            DateTime startDate   = DateTime.Parse(ini["DATES"]["startdate"]);
            DateTime stopDate    = DateTime.Parse(ini["DATES"]["enddate"]);
            Brush    headerColor = Brushes.LightGray;
            int      interval    = 1;
            int      rows        = 0;

            //Firste column color rec
            Rectangle recC = new Rectangle();

            recC.Fill = headerColor;
            Grid.SetColumn(recC, 0);
            Grid.SetRow(recC, 0);
            Children.Add(recC);

            //Defining rowdef & row height
            RowDefinition row    = new RowDefinition();
            GridLength    height = new GridLength(140);

            for (DateTime dateTime = startDate; dateTime <= stopDate; dateTime += TimeSpan.FromDays(interval))
            {
                if (dateTime.DayOfWeek != DayOfWeek.Sunday && dateTime.DayOfWeek != DayOfWeek.Saturday)
                {
                    //Adding color
                    Rectangle rec = new Rectangle();
                    rec.Fill = headerColor;
                    Grid.SetColumn(rec, 0);
                    Grid.SetRow(rec, rows);
                    Grid.SetColumnSpan(rec, classrooms.Count + 1);
                    Children.Add(rec);
                    //Add labels
                    for (int c = 0; c < classrooms.Count + 1; c++)
                    {
                        if (ColumnDefinitions.Count != classrooms.Count + 1)
                        {
                            //making columns
                            ColumnDefinition column = new ColumnDefinition();
                            GridLength       width;
                            if (c == 0)
                            {
                                width = new GridLength(75);
                            }
                            else
                            {
                                width = new GridLength(120);
                            }
                            column.Width = width;
                            ColumnDefinitions.Add(column);
                        }
                        //making labels
                        Label header = new Label();
                        if (c == 0)
                        {
                            header.Content = dateTime.ToString("dddd",
                                                               new CultureInfo("nl-NL")) + "\n" + dateTime.ToShortDateString();
                        }
                        else
                        {
                            header.Content = classrooms[c - 1].Room_number;
                        }
                        header.VerticalContentAlignment   = System.Windows.VerticalAlignment.Center;
                        header.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                        Grid.SetColumn(header, c);
                        Grid.SetRow(header, rows);
                        Children.Add(header);
                    }

                    List <Timeslot> timeslots = controller.Timeslots;

                    //Making rows
                    for (int block = 0; block < timeslots.Count; ++block)
                    {
                        row = new RowDefinition();
                        //blok 0 = row for headers(classrooms,date)
                        if (block == 0)
                        {
                            row.Height = new GridLength(60);
                        }
                        else
                        {
                            row.Height = height;
                        }
                        RowDefinitions.Add(row);
                        rows++;

                        Label blk = new Label();
                        blk.Content = timeslots[block].Time;
                        blk.VerticalContentAlignment   = System.Windows.VerticalAlignment.Center;
                        blk.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                        Grid.SetColumn(blk, 0);
                        Grid.SetRow(blk, rows);
                        Children.Add(blk);
                    }


                    //Maken dateGrids
                    Grid dateGrid = new Grid();
                    for (int i = 0; i < ColumnDefinitions.Count - 1; i++)
                    {
                        ColumnDefinition column = new ColumnDefinition();
                        GridLength       width  = new GridLength(120);
                        column.Width = width;
                        dateGrid.ColumnDefinitions.Add(column);
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        row        = new RowDefinition();
                        row.Height = height;
                        dateGrid.RowDefinitions.Add(row);
                    }

                    for (int j = 0; j < 4; j++)
                    {
                        for (int i = 0; i < dateGrid.ColumnDefinitions.Count; i++)
                        {
                            CustomLabel emptySession = new CustomLabel();
                            Grid.SetColumn(emptySession, i);
                            Grid.SetRow(emptySession, j);
                            emptySession.AllowDrop = true;
                            emptySession.Drop     += new DragEventHandler(Session_Drop);
                            dateGrid.Children.Add(emptySession);
                        }
                    }
                    Grid.SetColumn(dateGrid, 1);
                    Grid.SetColumnSpan(dateGrid, dateGrid.ColumnDefinitions.Count);
                    Grid.SetRow(dateGrid, rows - 3);
                    Grid.SetRowSpan(dateGrid, dateGrid.RowDefinitions.Count);
                    dateGrid.ShowGridLines = true;
                    dateGrids.Add(dateTime.ToShortDateString(), dateGrid);
                    Children.Add(dateGrid);

                    //row block 4
                    row        = new RowDefinition();
                    row.Height = height;
                    RowDefinitions.Add(row);
                    rows++;
                }
            }
            //set first column color over all rows
            Grid.SetRowSpan(recC, rows);
        }
示例#20
0
        private void set_initial_dir(string f)
        {
            var a = new Ini.IniFile(RubyCore.SelfPath + @"\settings.ini");

            a.IniWriteValue("InitFolder", "path", f);
        }
示例#21
0
        public static void Compile(FileInfo skinFileInfo, DirectoryInfo steamDirectoryInfo, DirectoryInfo baseDirectoryInfo = null)
        {
            if (!FreeImage.IsAvailable()) throw new Exception("FreeImage.dll not found");
            if (!skinFileInfo.Exists) throw new Exception("Definition file doesn't exist");
            if (!steamDirectoryInfo.Exists) throw new Exception("Steam directory doesn't exist");

            Dictionary<string, KeyValue> skinKeyValueList = new Dictionary<string, KeyValue>();

            JSchemaGenerator schemaGenerator = new JSchemaGenerator();

            JsonTextReader reader = new JsonTextReader(new StringReader(File.ReadAllText(skinFileInfo.FullName)));

            JSchemaValidatingReader validatingReader = new JSchemaValidatingReader(reader);
            validatingReader.Schema = schemaGenerator.Generate(typeof(SkinFile));
            SkinFile skinFile = new JsonSerializer().Deserialize<SkinFile>(validatingReader);

            string skinSourcePath;
            if (skinFile.metadata.template.skinBase == defaultSkinBaseName)
                skinSourcePath = steamDirectoryInfo.FullName + "/";
            else
            {
                string baseDirectory;
                if (baseDirectoryInfo != null)
                    baseDirectory = baseDirectoryInfo.FullName + "/" + skinFile.metadata.template.skinBase;
                else
                    baseDirectory = steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/" + skinFile.metadata.template.skinBase;

                skinSourcePath = baseDirectory + "/";
            }

            /// TODO: Make copy of 3rd party skin and use it as a base

            if (!Directory.Exists(skinSourcePath)) throw new Exception("Skin source '" + skinSourcePath + "' directory doesn't exist");

            if (skinFile.files != null)
            {
                // iterate through files
                foreach (KeyValuePair<string, SkinFile.File> f in skinFile.files)
                {
                    string path = skinSourcePath + f.Key;
                    if (!File.Exists(path))
                    {
                        StreamWriter writer = File.CreateText(path);
                        writer.WriteLine('"' + f.Key + '"');
                        writer.WriteLine('{');
                        writer.WriteLine('}');
                        writer.Close();
                    }
                    KeyValue kv = KeyValue.LoadFromString(KeyValue.NormalizeFileContent(path));
                    if (f.Value.remove is JArray)
                    {
                        foreach (JToken node in f.Value.remove.Children())
                            RemoveNode(kv, node);
                    }
                    if (f.Value.add is JObject)
                    {
                        foreach (JProperty node in f.Value.add.Children())
                            kv.Children.Add(CreateNode(kv, node));
                    }
                    if (f.Value.change is JObject)
                    {
                        // recursively iterate through sections and change all found keys
                        ChangeNode(kv, new JProperty(f.Key, f.Value.change), false);
                    }
                    skinKeyValueList.Add(f.Key, kv);
                }
            }

            //if (skinFile.metadata.folderName == null) throw new Exception("Undefined skin folder name");
            string folderName = skinFile.metadata.template.name;
            if (skinFile.metadata.skin.name != null && skinFile.metadata.skin.author != null)
                folderName = skinFile.metadata.skin.name + " #" + skinFile.metadata.skin.id;

            string destinationPath = steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/" + folderName;

            try
            {
                if (Directory.Exists(destinationPath))
                {
                    if (backupEnabled)
                    {
                        string backupDirectoryName = destinationPath + " - Backup (" + DateTime.Now.ToString("yyyyMMddHHmmss") + ")";
                        if (Directory.Exists(backupDirectoryName)) Directory.Delete(backupDirectoryName, true);
                        Directory.Move(destinationPath, backupDirectoryName);
                    }
                    else Directory.Delete(destinationPath, true);
                }

                Directory.CreateDirectory(destinationPath);

                /// NOTE: Copy base directory prior to writing modified files

                if (skinFile.metadata.template.skinBase != defaultSkinBaseName)
                    DirectoryCopy(skinSourcePath, destinationPath, true);

                foreach (KeyValuePair<string, KeyValue> kv in skinKeyValueList)
                {
                    if (Directory.CreateDirectory(destinationPath + "/" + Path.GetDirectoryName(kv.Key)).Exists)
                        kv.Value.SaveToFile(destinationPath + "/" + kv.Key, false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            if (skinFile.attachments != null)
            {
                foreach (SkinFile.Attachment attachment in skinFile.attachments)
                {
                    string type = (attachment.type != null) ? attachment.type : "image";

                    switch (type.ToLower())
                    {
                        case "image":
                            {
                                using (Base64Image image = new Base64Image(attachment.data))
                                {
                                    string graphicsDirPath = destinationPath + "/" + Path.GetDirectoryName(attachment.path);
                                    string extension = Path.GetExtension(attachment.path);
                                    if (extension.Length == 0)
                                        extension = "tga";
                                    else
                                        extension = extension.Substring(1);
                                    if (!Directory.Exists(graphicsDirPath)) Directory.CreateDirectory(graphicsDirPath);

                                    if (attachment.filters != null)
                                        image.ApplyFilters(attachment.filters);

                                    if (attachment.spritesheet == null)
                                    {
                                        if (attachment.transform != null)
                                            image.Transform(attachment.transform);
                                        image.Save(graphicsDirPath + "/" + Path.GetFileNameWithoutExtension(attachment.path) + "." + extension);
                                    }
                                    else // has defined spritesheet
                                    {
                                        string spritePath, finalPath = null;
                                        foreach (KeyValuePair<int, int[]> spriteDefinition in attachment.spritesheet)
                                        {
                                            if (spriteDefinition.Value.Length == 4)
                                            {
                                                if (attachment.spritesheetFiles.TryGetValue(spriteDefinition.Key, out spritePath))
                                                {
                                                    string dir = destinationPath + "/" + Path.GetDirectoryName(spritePath);
                                                    if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
                                                    finalPath = dir + "/" + Path.GetFileNameWithoutExtension(spritePath) + "." + extension;
                                                }
                                                else
                                                    finalPath = graphicsDirPath + "/" + Path.GetFileNameWithoutExtension(attachment.path) + spriteDefinition.Key + "." + extension;

                                                if (finalPath != null)
                                                    image.SaveSprite(finalPath, spriteDefinition.Value);
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                    }
                }
            }

            // write metadata
            //string iniTemplateSection = "Template",
            //       iniSkinSection = "Skin";
            Ini.IniFile metadataIni = new Ini.IniFile(destinationPath + "/metadata.ini");
            foreach (PropertyInfo metadata in skinFile.metadata.GetType().GetProperties())
            {
                char[] arr = metadata.Name.ToCharArray();
                arr[0] = char.ToUpperInvariant(arr[0]);
                string sectionName = new string(arr);

                PropertyInfo sectionInfo = skinFile.metadata.GetType().GetProperty(metadata.Name);
                if (sectionInfo != null)
                {
                    object section = sectionInfo.GetValue(skinFile.metadata, null);
                    foreach (PropertyInfo property in section.GetType().GetProperties())
                    {
                        arr = property.Name.ToCharArray();
                        arr[0] = char.ToUpperInvariant(arr[0]);
                        string propertyName = new string(arr);

                        object val = property.GetValue(section, null);
                        string propertyValue = (val == null) ? "" : property.GetValue(section, null).ToString();
                        switch (property.Name)
                        {
                            case "revision":
                                {
                                    if (Convert.ToInt32(propertyValue) > 0)
                                        metadataIni.IniWriteValue(sectionName, propertyName, propertyValue);
                                    break;
                                }
                            case "primaryColor":
                            case "primaryTextColor":
                            case "accentColor":
                            case "accentTextColor":
                                {
                                    if (propertyValue.Length > 0)
                                        metadataIni.IniWriteValue(sectionName, propertyName, "0x" + propertyValue);
                                    break;
                                }
                            case "thumbnail":
                                {
                                    try
                                    {
                                        string fileName = "thumb.jpg";
                                        using (Base64Image image = new Base64Image(propertyValue))
                                        {
                                            if (image.Save(destinationPath + "/" + fileName, FREE_IMAGE_FORMAT.FIF_JPEG, FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB))
                                                metadataIni.IniWriteValue(sectionName, propertyName, fileName);
                                        }
                                    }
                                    catch { }
                                    break;
                                }
                            default:
                                {
                                    if (propertyValue.Length > 0)
                                        metadataIni.IniWriteValue(sectionName, propertyName, propertyValue);
                                    break;
                                }
                        }
                    }
                }
                //Console.WriteLine(skinFile.metadata.GetType().GetProperty(metadata.Name).Name);
                /*
                foreach (PropertyInfo field in skinFile.metadata.GetType().GetField(metadata.Name).GetType().GetProperties())
                {
                    Console.WriteLine(field);
                }
                */
            }
            /*
            metadataIni.IniWriteValue(iniTemplateSection, "Version", skinFile.metadata.template);
            metadataIni.IniWriteValue(iniTemplateSection, "Name", skinFile.metadata.name);
            metadataIni.IniWriteValue(iniTemplateSection, "Author", skinFile.metadata.author);
            metadataIni.IniWriteValue(iniTemplateSection, "AuthorUrl", skinFile.metadata.authorUrl != null ? skinFile.metadata.authorUrl : "");
            metadataIni.IniWriteValue(iniTemplateSection, "SkinURL", skinFile.metadata.skinURL != null ? skinFile.metadata.skinURL : "");
            metadataIni.IniWriteValue(iniTemplateSection, "Description", skinFile.metadata.description != null ? skinFile.metadata.description : "");
            metadataIni.IniWriteValue(iniTemplateSection, "Color", skinFile.metadata.color != null ? skinFile.metadata.color : "0x1E1E1E");
            */
            // activate skin
            File.Delete(steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/.active");
            if (activateSkin)
                File.WriteAllText(steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/.active", folderName);

            // print debug
            if (debugMode)
            {
                string buffer = "";
                buffer += "Steam Customizer compiler debug log @ " + DateTime.Now.ToString() + "\r\n";
                buffer += "Schema list:\r\n";
                foreach (Type t in new Type[] { typeof(SkinFile) })
                {
                    buffer += "\r\n" + t.ToString() + ":\r\n";
                    buffer += schemaGenerator.Generate(t).ToString();
                    buffer += "\r\n";
                }
                File.WriteAllText("debug.log", buffer);
            }
        }
示例#22
0
        static public void Compile(FileInfo skinFileInfo, DirectoryInfo steamDirectoryInfo, DirectoryInfo baseDirectoryInfo = null)
        {
            if (!FreeImage.IsAvailable())
            {
                throw new Exception("FreeImage.dll not found");
            }
            if (!skinFileInfo.Exists)
            {
                throw new Exception("Definition file doesn't exist");
            }
            if (!steamDirectoryInfo.Exists)
            {
                throw new Exception("Steam directory doesn't exist");
            }

            Dictionary <string, KeyValue> skinKeyValueList = new Dictionary <string, KeyValue>();

            JSchemaGenerator schemaGenerator = new JSchemaGenerator();

            JsonTextReader reader = new JsonTextReader(new StringReader(File.ReadAllText(skinFileInfo.FullName)));

            JSchemaValidatingReader validatingReader = new JSchemaValidatingReader(reader);

            validatingReader.Schema = schemaGenerator.Generate(typeof(SkinFile));
            SkinFile skinFile = new JsonSerializer().Deserialize <SkinFile>(validatingReader);

            string skinSourcePath;

            if (skinFile.metadata.template.skinBase == defaultSkinBaseName)
            {
                skinSourcePath = steamDirectoryInfo.FullName + "/";
            }
            else
            {
                string baseDirectory;
                if (baseDirectoryInfo != null)
                {
                    baseDirectory = baseDirectoryInfo.FullName + "/" + skinFile.metadata.template.skinBase;
                }
                else
                {
                    baseDirectory = steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/" + skinFile.metadata.template.skinBase;
                }

                skinSourcePath = baseDirectory + "/";
            }

            /// TODO: Make copy of 3rd party skin and use it as a base

            if (!Directory.Exists(skinSourcePath))
            {
                throw new Exception("Skin source '" + skinSourcePath + "' directory doesn't exist");
            }

            if (skinFile.files != null)
            {
                // iterate through files
                foreach (KeyValuePair <string, SkinFile.File> f in skinFile.files)
                {
                    string path = skinSourcePath + f.Key;
                    if (!File.Exists(path))
                    {
                        StreamWriter writer = File.CreateText(path);
                        writer.WriteLine('"' + f.Key + '"');
                        writer.WriteLine('{');
                        writer.WriteLine('}');
                        writer.Close();
                    }
                    KeyValue kv = KeyValue.LoadFromString(KeyValue.NormalizeFileContent(path));
                    if (f.Value.remove is JArray)
                    {
                        foreach (JToken node in f.Value.remove.Children())
                        {
                            RemoveNode(kv, node);
                        }
                    }
                    if (f.Value.add is JObject)
                    {
                        foreach (JProperty node in f.Value.add.Children())
                        {
                            kv.Children.Add(CreateNode(kv, node));
                        }
                    }
                    if (f.Value.change is JObject)
                    {
                        // recursively iterate through sections and change all found keys
                        ChangeNode(kv, new JProperty(f.Key, f.Value.change), false);
                    }
                    skinKeyValueList.Add(f.Key, kv);
                }
            }

            //if (skinFile.metadata.folderName == null) throw new Exception("Undefined skin folder name");
            string folderName = skinFile.metadata.template.name;

            if (skinFile.metadata.skin.name != null && skinFile.metadata.skin.author != null)
            {
                folderName = skinFile.metadata.skin.name + " #" + skinFile.metadata.skin.id;
            }

            string destinationPath = steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/" + folderName;

            try
            {
                if (Directory.Exists(destinationPath))
                {
                    if (backupEnabled)
                    {
                        string backupDirectoryName = destinationPath + " - Backup (" + DateTime.Now.ToString("yyyyMMddHHmmss") + ")";
                        if (Directory.Exists(backupDirectoryName))
                        {
                            Directory.Delete(backupDirectoryName, true);
                        }
                        Directory.Move(destinationPath, backupDirectoryName);
                    }
                    else
                    {
                        Directory.Delete(destinationPath, true);
                    }
                }

                Directory.CreateDirectory(destinationPath);

                /// NOTE: Copy base directory prior to writing modified files

                if (skinFile.metadata.template.skinBase != defaultSkinBaseName)
                {
                    DirectoryCopy(skinSourcePath, destinationPath, true);
                }

                foreach (KeyValuePair <string, KeyValue> kv in skinKeyValueList)
                {
                    if (Directory.CreateDirectory(destinationPath + "/" + Path.GetDirectoryName(kv.Key)).Exists)
                    {
                        kv.Value.SaveToFile(destinationPath + "/" + kv.Key, false);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            if (skinFile.attachments != null)
            {
                foreach (SkinFile.Attachment attachment in skinFile.attachments)
                {
                    string type = (attachment.type != null) ? attachment.type : "image";

                    switch (type.ToLower())
                    {
                    case "image":
                    {
                        using (Base64Image image = new Base64Image(attachment.data))
                        {
                            string graphicsDirPath = destinationPath + "/" + Path.GetDirectoryName(attachment.path);
                            string extension       = Path.GetExtension(attachment.path);
                            if (extension.Length == 0)
                            {
                                extension = "tga";
                            }
                            else
                            {
                                extension = extension.Substring(1);
                            }
                            if (!Directory.Exists(graphicsDirPath))
                            {
                                Directory.CreateDirectory(graphicsDirPath);
                            }

                            if (attachment.filters != null)
                            {
                                image.ApplyFilters(attachment.filters);
                            }

                            if (attachment.spritesheet == null)
                            {
                                if (attachment.transform != null)
                                {
                                    image.Transform(attachment.transform);
                                }
                                image.Save(graphicsDirPath + "/" + Path.GetFileNameWithoutExtension(attachment.path) + "." + extension);
                            }
                            else         // has defined spritesheet
                            {
                                string spritePath, finalPath = null;
                                foreach (KeyValuePair <int, int[]> spriteDefinition in attachment.spritesheet)
                                {
                                    if (spriteDefinition.Value.Length == 4)
                                    {
                                        if (attachment.spritesheetFiles.TryGetValue(spriteDefinition.Key, out spritePath))
                                        {
                                            string dir = destinationPath + "/" + Path.GetDirectoryName(spritePath);
                                            if (!Directory.Exists(dir))
                                            {
                                                Directory.CreateDirectory(dir);
                                            }
                                            finalPath = dir + "/" + Path.GetFileNameWithoutExtension(spritePath) + "." + extension;
                                        }
                                        else
                                        {
                                            finalPath = graphicsDirPath + "/" + Path.GetFileNameWithoutExtension(attachment.path) + spriteDefinition.Key + "." + extension;
                                        }

                                        if (finalPath != null)
                                        {
                                            image.SaveSprite(finalPath, spriteDefinition.Value);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }
                }
            }

            // write metadata
            //string iniTemplateSection = "Template",
            //       iniSkinSection = "Skin";
            Ini.IniFile metadataIni = new Ini.IniFile(destinationPath + "/metadata.ini");
            foreach (PropertyInfo metadata in skinFile.metadata.GetType().GetProperties())
            {
                char[] arr = metadata.Name.ToCharArray();
                arr[0] = char.ToUpperInvariant(arr[0]);
                string sectionName = new string(arr);

                PropertyInfo sectionInfo = skinFile.metadata.GetType().GetProperty(metadata.Name);
                if (sectionInfo != null)
                {
                    object section = sectionInfo.GetValue(skinFile.metadata, null);
                    foreach (PropertyInfo property in section.GetType().GetProperties())
                    {
                        arr    = property.Name.ToCharArray();
                        arr[0] = char.ToUpperInvariant(arr[0]);
                        string propertyName = new string(arr);

                        object val           = property.GetValue(section, null);
                        string propertyValue = (val == null) ? "" : property.GetValue(section, null).ToString();
                        switch (property.Name)
                        {
                        case "revision":
                        {
                            if (Convert.ToInt32(propertyValue) > 0)
                            {
                                metadataIni.IniWriteValue(sectionName, propertyName, propertyValue);
                            }
                            break;
                        }

                        case "primaryColor":
                        case "primaryTextColor":
                        case "accentColor":
                        case "accentTextColor":
                        {
                            if (propertyValue.Length > 0)
                            {
                                metadataIni.IniWriteValue(sectionName, propertyName, "0x" + propertyValue);
                            }
                            break;
                        }

                        case "thumbnail":
                        {
                            try
                            {
                                string fileName = "thumb.jpg";
                                using (Base64Image image = new Base64Image(propertyValue))
                                {
                                    if (image.Save(destinationPath + "/" + fileName, FREE_IMAGE_FORMAT.FIF_JPEG, FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB))
                                    {
                                        metadataIni.IniWriteValue(sectionName, propertyName, fileName);
                                    }
                                }
                            }
                            catch { }
                            break;
                        }

                        default:
                        {
                            if (propertyValue.Length > 0)
                            {
                                metadataIni.IniWriteValue(sectionName, propertyName, propertyValue);
                            }
                            break;
                        }
                        }
                    }
                }
                //Console.WriteLine(skinFile.metadata.GetType().GetProperty(metadata.Name).Name);

                /*
                 * foreach (PropertyInfo field in skinFile.metadata.GetType().GetField(metadata.Name).GetType().GetProperties())
                 * {
                 *  Console.WriteLine(field);
                 * }
                 */
            }

            /*
             * metadataIni.IniWriteValue(iniTemplateSection, "Version", skinFile.metadata.template);
             * metadataIni.IniWriteValue(iniTemplateSection, "Name", skinFile.metadata.name);
             * metadataIni.IniWriteValue(iniTemplateSection, "Author", skinFile.metadata.author);
             * metadataIni.IniWriteValue(iniTemplateSection, "AuthorUrl", skinFile.metadata.authorUrl != null ? skinFile.metadata.authorUrl : "");
             * metadataIni.IniWriteValue(iniTemplateSection, "SkinURL", skinFile.metadata.skinURL != null ? skinFile.metadata.skinURL : "");
             * metadataIni.IniWriteValue(iniTemplateSection, "Description", skinFile.metadata.description != null ? skinFile.metadata.description : "");
             * metadataIni.IniWriteValue(iniTemplateSection, "Color", skinFile.metadata.color != null ? skinFile.metadata.color : "0x1E1E1E");
             */
            // activate skin
            File.Delete(steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/.active");
            if (activateSkin)
            {
                File.WriteAllText(steamDirectoryInfo.FullName + "/" + defaultSkinFolderName + "/.active", folderName);
            }

            // print debug
            if (debugMode)
            {
                string buffer = "";
                buffer += "Steam Customizer compiler debug log @ " + DateTime.Now.ToString() + "\r\n";
                buffer += "Schema list:\r\n";
                foreach (Type t in new Type[] { typeof(SkinFile) })
                {
                    buffer += "\r\n" + t.ToString() + ":\r\n";
                    buffer += schemaGenerator.Generate(t).ToString();
                    buffer += "\r\n";
                }
                File.WriteAllText("debug.log", buffer);
            }
        }