Example #1
0
        public static void Main(String[] args)
        {
            // This fixes the current directory in case it is run from outside the launcher path.
            Environment.CurrentDirectory = Path.GetDirectoryName(typeof(SharpCraftApplication).Assembly.Location);

            // Check for optional map specified to launch
            string mapFile = ""; // Is there a loadfile arg specified?
            for (var i = 0; i < args.Length; i++)
            {
                if (args[i] == "-loadfile" && args.Last() != "-loadfile") // if -loadfile and there are still more args to read
                {
                    // check the argument immediately to the right... it should be a map file (w3x or w3m) or a replay (w3g)
                    if (args[i + 1].EndsWith(".w3x") || args[i + 1].EndsWith(".w3m") || args[i + 1].EndsWith(".w3g"))
                    {
                        mapFile = args[i + 1];
                        // clean string and wrap in quotes because path may contain spaces
                        // note: even when passing in the arg in quotes, those will "disappear", so quotes are re-applied
                        args[i + 1] = "\"" + args[i + 1].Trim() + "\"";
                    }
                    else
                    {
                        Console.WriteLine("The -loadfile param was specified, but was not immediately followed by a valid WarCraft map to open.");
                    }
                }
                else
                {
                    Console.WriteLine("The -loadfile param was specified, but no more valid arguments follow it!");
                }
            }

            if (args.Contains("-game") || args.Contains("-editor"))
            {
                Debug.WriteLineIf(args.Contains("-game"), args.Aggregate((a, b) => a + ' ' + b));
                Debug.WriteLineIf(mapFile.Length > 0, "Starting game with map: " + mapFile);
                StartDirect(args);
            }
            else
            {
                StartLauncher(args);
            }
        }
Example #2
0
        public static String FindFile(String baseFolder, String fileName)
        {
            baseFolder = baseFolder.Replace('/', '\\');
            if (baseFolder.Last() != '\\')
            {
                baseFolder += '\\';
            }

            var path = Path.Combine(baseFolder, fileName);
            path = path.Replace('/', '\\');

            var folder = Path.GetDirectoryName(fileName);
            var file = Path.GetFileName(path);
            var pathFolder = Path.GetDirectoryName(path);

            if (!String.IsNullOrEmpty(pathFolder))
            {
                return Directory.GetFiles(pathFolder)
                    .FirstOrDefault(f => f.ToLower().Contains(Path.GetFileName(path).ToLower()));
            }
            return null;
        }
Example #3
0
 public void Write(String str)
 {
     this.FixStateToConsole();
     this.CursorPosition = str
         .Scan(this.CursorPosition, (p, c) => p.Move(c))
         .StartWith(this.CursorPosition)
         .EndWith(this.CursorPosition.Move(GetWidth(str)))
         .Zip(str, Tuple.Create)
         .Do(_ =>
             {
                 System.Diagnostics.Debug.WriteLine(_);
                 this._cells[this.CursorIndex] = new Cell(_.Item2);
                 this.CursorIndex.CompareTo(this._buffer.Length).If(
                     i => i < 0,
                     i => this._buffer[this.CursorIndex] = _.Item2,
                     i => (i > 0
                         ? this._buffer.Append(' ', this.CursorIndex - this._buffer.Length - 1)
                         : this._buffer
                     ).Append(_.Item2)
                 );
                 if (this.IsVisible(_.Item1))
                 {
                     Console.SetCursorPosition(_.Item1.Left, _.Item1.Top);
                     Console.Write(_.Item2);
                     this.FixStateFromConsole();
                 }
             })
         .Last()
         .Item1
         .Move(str.Last());
     this.FixStateFromConsole();
 }
Example #4
0
        /// <summary>
        /// Creates a relative path from one file or folder to another.
        /// </summary>
        /// <param name="fromPath">Contains the directory that defines the start of the relative path.</param>
        /// <param name="toPath">Contains the path that defines the endpoint of the relative path.</param>
        /// <param name="dontEscape">Boolean indicating whether to add uri safe escapes to the relative path</param>
        /// <returns>The relative path from the start directory to the end path.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static String MakeRelativePath(String fromPath, String toPath)
        {
            if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
            if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");

            if (fromPath.Last() != '\\')
                fromPath = fromPath + "\\";

            Uri fromUri = new Uri(fromPath);
            Uri toUri = new Uri(toPath);

            Uri relativeUri = fromUri.MakeRelativeUri(toUri);
            String relativePath = Uri.UnescapeDataString(relativeUri.ToString());

            return relativePath.Replace('/', Path.DirectorySeparatorChar);
        }
        //<summary>Checks of the folder already exists as an album on flickr and synchronizes all folder in the current folder.</summary>
        void SyncFolder(String path)
        {
            String[] picture_files = m_folder_enum.GetFilesOfType(path, m_pictures_suffixes);

            if (!(path.Last() == Path.DirectorySeparatorChar))
                path += Path.DirectorySeparatorChar;

            String base_path = Path.GetDirectoryName(path).Split(Path.DirectorySeparatorChar).Last();
            String photoset_id;

            if (picture_files.Length < 1) return;

            if (!m_flickr_connect.PhotoSetExists(base_path))
            {
                m_flickr_connect.AddSet(null, base_path, picture_files[0]);
                picture_files = picture_files.Skip(1).ToArray();
            }

            photoset_id = m_flickr_connect.GetPhotoSetByName(base_path);

            SyncFilesToSet(photoset_id, picture_files);
        }
        private static int ParseSeconds(String timespan)
        {
            const string format = "Timespan must be in the format <int>[unit] where unit is s, m, h";

            if(String.IsNullOrEmpty(timespan))
            {
                throw new ArgumentException(format);
            }

            int multiplier = 1;

            if(Char.IsLetter(timespan.Last()))
            {
                var units = new[] {'s', 'h', 'm'};

                if(!units.Any(s => s == timespan.Last()))
                {
                    throw new ArgumentException(format);
                }

                switch(timespan.Last())
                {
                    case ('h'):
                        multiplier = 3600;
                        break;
                    case ('m'):
                        multiplier = 60;
                        break;
                }
            }

            string amountString = timespan;

            if(Char.IsLetter(timespan.Last()))
            {
                amountString = timespan.Remove(timespan.Length - 1);
            }

            int amount;

            if(!int.TryParse(amountString, out amount))
            {
                throw new ArgumentException(format);
            }

            return amount * multiplier;
        }
Example #7
0
        public FibeClass JoinClass(String[] path)
        {
            StringBuilder sb = new StringBuilder();
            FibeClass c;
            foreach (String s in path)
            {
                sb.Append(s);
                if (s != path.Last()) sb.Append(", ");
            }

            if (classJoined.ContainsKey(sb.ToString()))
            {
                c = classJoined[sb.ToString()];
            } else {
                c = new FibeClass(path);
                classJoined.Add(sb.ToString(), c);
                c.client = this;
                c.Title = sb.ToString() + " - " + sessionID;
                c.connector = connector;
            }
            return c;
        }
Example #8
0
        private void LoadData()
        {
            var from = (IDictionary<string, object>)posts["from"];

            InlineUIContainer uiContainer = new InlineUIContainer();
            uiContainer.Child = new UserLinks((String)from["name"], -4);
            Story.Inlines.Add(uiContainer);

            string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", (String)from["id"], "square", _fb.AccessToken);
            UserPic.Source = new BitmapImage(new Uri(profilePictureUrl));
            
            String storytxt = "";
            String story_tag = "";
            dynamic selected_tagDic = null;
            String message = "";
            int message_tagsCount = 0;
            try
            {
                storytxt = (String)posts["story"];
            }
            catch (Exception e) { }

            try
            {
                if (((String)posts["type"]).Equals("link"))
                {
                    var application = (IDictionary<string, object>)posts["application"];
                    if (((String)application["namespace"]).Equals("likes"))
                    {
                        storytxt = " likes a link.";
                    }
                }
            }
            catch (Exception e) { }
            IDictionary<string, object> message_tagsDic = null;
            try
            {
                message_tagsDic = (IDictionary<string, object>)posts["message_tags"];
            }
            catch (Exception e) { }

            try
            {
                var story_tagsDic = (IDictionary<string, object>)posts["story_tags"];
                var story_tagsSecondEl = (IEnumerable<object>)story_tagsDic.ElementAt(1).Value;
                var selected_tag = story_tagsSecondEl.ElementAt(0);
                selected_tagDic = (IDictionary<string, object>)selected_tag;

                story_tag = (String)selected_tagDic["name"]; ;
            }
            catch (Exception e) { }

            try { message = (String)posts["message"]; }
            catch (Exception e) { }

            try
            {
                var message_tagsDicForCount = (IDictionary<string, object>)posts["message_tags"];
                message_tagsCount = message_tagsDicForCount.Count;
            }
            catch (Exception e) { }

            Run pText = new Run();
            //pText.Foreground = new SolidColorBrush(Color.FromArgb(255, 129,129,129));
            pText.Text = storytxt.Replace((String)from["name"], "");
            Story.Inlines.Add(pText);

            if (!story_tag.Equals(""))
            {
                String[] storyTextSplit = new String[] { storytxt.Substring(0, (int)selected_tagDic["offset"]), storytxt.Substring((int)selected_tagDic["offset"] + story_tag.Length) };
                
                pText.Text = storyTextSplit[0].Replace((String)from["name"], "");
                uiContainer = new InlineUIContainer();
                uiContainer.Child = new UserLinks(story_tag, false, -4);
                Story.Inlines.Add(uiContainer);
                pText = new Run();
                pText.Text = storyTextSplit.Last();
                Story.Inlines.Add(pText);
            }

            if (message_tagsDic == null)
            {
                Run r = new Run();
                r.Text = message;
                Message.Inlines.Add(r);
            }
            else
            {
                String[] modMessage = new String[]{message};
                Run r;
                int offset = 0;
                for (int i = 0; i < message_tagsDic.Count; i++)
                {
                    var message_tagEl = (IEnumerable<object>)message_tagsDic.ElementAt(i).Value;
                    dynamic message_selTag = message_tagEl.ElementAt(0);
                    message_selTag = (IDictionary<string, object>)message_selTag;
                    String message_tagName = (String)message_selTag["name"];

                    modMessage = new String[] { modMessage[0].Substring(0, (int)message_selTag["offset"]-offset), modMessage[0].Substring((int)message_selTag["offset"] - offset + message_tagName.Length) };
                    offset = message_tagName.Length + (int)message_selTag["offset"];

                    r = new Run();
                    r.Text = modMessage[0];
                    Message.Inlines.Add(r);

                    uiContainer = new InlineUIContainer();
                    uiContainer.Child = new UserLinks(message_tagName, false, -3);
                    Message.Inlines.Add(uiContainer);

                    modMessage = new String[] { modMessage[1] };
                }
                r = new Run();
                r.Text = modMessage[0];
                Message.Inlines.Add(r);
            }

            if (((String)posts["type"]).Equals("photo"))
            {
                ImagePost image = new ImagePost();

                string photoFormat = string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", posts["object_id"], _fb.AccessToken);

                BitmapImage photo = new BitmapImage(new Uri(photoFormat));

                image.postImage.Source = photo;
                StatusArea.Children.Insert(StatusArea.Children.Count()-1, image);
            }

            statusControls = new StatusControls(posts, _fbSession);
            StatusControlSection.Children.Add(statusControls);
        }
        private void loadSlideFolder()
        {
            VarParser.XMLrequire(config, "conf");

            IEnumerable<XElement> elements =
            from el in config.Elements()
            where el.Name == "includes"
            select el;

            XElement econf = elements.First();
            VarParser.XMLrequire(econf, "includes");

            elements =
            from el in econf.Elements()
            where el.Name == "slidefolder"
            select el;

            if(elements.Count() ==1)
                if (elements.First().Attribute("src") != null)
                {
                    slidefolder = elements.First().Attribute("src").Value.ToString();
                    if (slidefolder.Last() != '\\')
                        slidefolder = slidefolder + "\\";


                    if (!Directory.Exists(slidefolder) && ApplicationDeployment.IsNetworkDeployed)
                        slidefolder = ApplicationDeployment.CurrentDeployment.DataDirectory + "\\" + slidefolder;
                    Console.WriteLine("NEW SlideFolder: " + slidefolder);
                }

        }
Example #10
0
 protected Int32 ParseNum(String s)
 {
     Int32 value;
     if(s.Length > 0 && s[0] == '$')
     {
         value = Int32.Parse(s.Substring(1), NumberStyles.HexNumber);
     }
     else if (s.Length > 2 && s[1] == 'x')
     {
         value = Int32.Parse(s.Substring(2), NumberStyles.HexNumber);
     }
     else if (s.Length > 1 && s.Last() == 'h' || s.Last() == 'H')
     {
         value = Int32.Parse(s.Substring(0, s.Length-1), NumberStyles.HexNumber);
     }
     else
     {
         value = Int32.Parse(s);
     }
     if (value > Int16.MaxValue || value < Int16.MinValue)
     {
         ErrorMsg("Integer cannot be represented in 16 bits");
     }
     return value;
 }
Example #11
0
 /// <summary>
 /// Creates a <see cref="TextExpression"/> that represents a string or a character from specified source string.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="text">The string which contains quoting characters..</param>
 /// <returns>An <see cref="TextExpression"/> which generates a string or a character from specified string.</returns>
 public static TextExpression Text(SymbolTable symbols, String text)
 {
     return String.IsNullOrEmpty(text) || text.First() != text.Last()
         ? Text(symbols, default(Char), text)
         : Text(symbols, text.First(), text.Substring(1, text.Length - 2));
 }