Exemplo n.º 1
0
 /// <summary>
 /// Saves the clippy.
 /// </summary>
 /// <param name='board'>
 /// Board.
 /// </param>
 public void saveClippy(Clippy board)
 {
     //thanks to the good people @ stackoverflow!
     string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
            Environment.OSVersion.Platform == PlatformID.MacOSX)
             ? Environment.GetEnvironmentVariable("HOME")
             : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
     string clipSave = homePath + "/.boomsharp";
     Stream stream = File.Open(clipSave, FileMode.Create);
     BinaryFormatter bFormatter = new BinaryFormatter();
     bFormatter.Serialize(stream, board);
     stream.Close();
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            //boomsharp usage
            //booms.exe <list> <name> <value>

            //first find the platform that we're on!
            //'w' = windows
            //'l' = linux
            //'m' = mac
            char pFrom = getPlatform();

            Clippy board = new Clippy();
            string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
                   Environment.OSVersion.Platform == PlatformID.MacOSX)
                    ? Environment.GetEnvironmentVariable("HOME")
                    : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
            string clipSave = homePath + "/.boomsharp";

            //check to see if we have an existing clipboard
            if (File.Exists(clipSave))
            {
                board = new Clippy().loadClippy();
            }
            //otherwise, just use this other one that we've got
            string aList = String.Empty;
            string aName = String.Empty;
            List<string> toCopy = new List<string>();

            //first just check if we have args
            if (args.Length > 0)
            {
                //now parse the input
                aList = args[0]; //the "BIG" bucket, bucket of litt

                if (args.Length > 1)
                {
                    aName = args[1];
                }

                if (args.Length > 2)
                {
                    for (int ii = 2; ii < args.Length; ii++)
                    {
                        toCopy.Add(args[ii]);
                    }
                }
            }

            //now, first case (noargs)
            if (args.Length == 0)
            {
                foreach (KeyValuePair<string, Dictionary<string, string>> kvp in board.savedItems)
                {
                    System.Console.WriteLine(kvp.Key + " (" + kvp.Value.Count + ")");
                }
            }
            //first args case!
            else if (args.Length == 1)
            {
                if (aList == "all") //first check special case!
                {
                    //print out EVERYTHING
                    foreach (KeyValuePair<string, Dictionary<string, string>> kvp in board.savedItems)
                    {
                        System.Console.WriteLine(kvp.Key);
                        foreach (KeyValuePair<string, string> sstr in kvp.Value)
                        {
                            System.Console.WriteLine("\t" + sstr.Key + " \t " + sstr.Value);
                        }
                    }
                }
                else if (!(board.savedItems.ContainsKey(aList)))
                {
                    board.savedItems[aList] = new Dictionary<string, string>();
                    System.Console.WriteLine("Boom! Created a new list called \"" + aList + "\".");
                    board.saveClippy(board);
                }

                else
                {
                    //just do some printing
                    foreach (KeyValuePair<string, string> kvp in board.savedItems[aList])
                    {
                        System.Console.WriteLine(kvp.Key + " " + kvp.Value);
                    }
                }
            }

            else if (args.Length == 2)
            {
                //first check special cases
                if (aName == "delete")
                {
                    //delete the entire list
                    if (board.savedItems.ContainsKey(aList))
                    {
                        if (okToDel(aList))
                        {
                            board.savedItems.Remove(aList);
                            System.Console.WriteLine("Boom! Deleted all your " + aList + ".");
                            board.saveClippy(board);
                        }
                    }
                }
                else if (aList == "open")
                {
                    //open each of the items in the browser
                    if (board.savedItems.ContainsKey(aName))
                    {
                        Dictionary<string, string> dItems = board.savedItems[aName];
                        foreach (KeyValuePair<string, string> kvp in dItems)
                        {
                            openInBrowser(kvp.Value, pFrom);
                        }
                        System.Console.WriteLine("Boom! We just opened all of \"" + aName + "\" for you.");
                    }
                }
                else if (aList == "echo")
                {
                    if (board.savedItems.ContainsKey(aName))
                    {
                        //just do some printing
                        foreach (KeyValuePair<string, string> kvp in board.savedItems[aName])
                        {
                            System.Console.WriteLine(kvp.Key + " " + kvp.Value);
                        }
                    }
                }
                else //so, goes list name, then copy to board
                {
                    if (board.savedItems.ContainsKey(aList))
                    {
                        Dictionary<string, string> dstr = board.savedItems[aList];
                        if (dstr.ContainsKey(aName))
                        {
                            clipString(dstr[aName], pFrom);
                        }
                    }
                }

            }
            else
            {
                //more than 2 args
                //first check the special cases
                if (toCopy[0] == "delete")
                {
                    if (board.savedItems.ContainsKey(aList) && board.savedItems[aList].ContainsKey(aName))
                    {
                        board.savedItems[aList].Remove(aName);
                        System.Console.WriteLine("Boom! \"" + aName +"\" is gone forever.");
                    }
                }
                else if (aList == "open")
                {
                    if(board.savedItems.ContainsKey(aName) && board.savedItems[aName].ContainsKey(toCopy[0]))
                    {
                        openInBrowser(board.savedItems[aName][toCopy[0]], pFrom);
                        System.Console.WriteLine("Boom! We just opened " + board.savedItems[aName][toCopy[0]] +" for you.");
                    }
                }
                else if (aList == "echo")
                {
                    //just print it out!
                    if (board.savedItems.ContainsKey(aName) && board.savedItems[aName].ContainsKey(toCopy[0]))
                    {
                        System.Console.WriteLine(board.savedItems[aName][toCopy[0]]);
                    }
                }
                else
                {
                    //just the save to clipboard
                    string str = String.Empty;
                    foreach(string ing in toCopy)
                    {
                        str += ing + " ";
                    }
                    str = str.Substring(0,str.Length - 1);
                    if (board.savedItems.ContainsKey(aList))
                    {
                        if (board.savedItems[aList].ContainsKey(aName))
                        {
                            board.savedItems[aList].Remove(aName);
                        }
                        board.savedItems[aList].Add(aName,str);
                        System.Console.WriteLine("Boom! \"" + aName + "\" in \"" + aList + "\" is \"" + str + "\". Got it.");

                    }
                }
                board.saveClippy(board);

            }
        }