Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int    iDirNum       = 0;
            string strGaneEnd    = ""; //w for in or l for loss
            bool   bIsThere      = false;
            string strSpiderBin0 = "";
            string PathToDirectory;
            string strSpiderBin;
            string strDesktop    = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string strResultName = DateTime.Now.Year.ToString();
            string PathToResult  = strDesktop + "\\" + strResultName;
            string dFile         = "";
            string stTemp        = System.Reflection.Assembly.GetEntryAssembly().Location; // path to executable
                                                                                           // KnownFolderFinder.EnumerateKnownFolders();   // this was used for testing purposes
                                                                                           // GlobalClass.InitExceptions();
                                                                                           // look for file in current director and use that one
            string strName;
            string strFrom;

            strSpiderBin0 = System.IO.Path.GetDirectoryName(stTemp) + "\\Spider Solitaire.SpiderSolitaireSave-ms";
            bIsThere      = File.Exists(strSpiderBin0);
            if (!bIsThere)
            {
                //Attempt to find where the saved spider file is located.  Normally at c:\user\username but the windows MOVE property might
                //have been used to relocat the file.  In addition,  OneDrive may or may not be in the path returned by SpecialFolder

                strSpiderBin0 = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                // the above is usually user\stateson\documents
                strSpiderBin = strSpiderBin0.Replace("Documents", "Saved Games\\Microsoft Games\\Spider Solitaire\\Spider Solitaire.SpiderSolitaireSave-ms");
                bIsThere     = File.Exists(strSpiderBin);
                if (!bIsThere)
                {
                    // user has made it hard to find, try looking in the registry in case the windows 10 "MOVE" relocated Documents.
                    // we need to find the original Documents location, not the new one
                    PathToDirectory = KnownFolderFinder.GetFolderFromKnownFolderGUID(new Guid("{FDD39AD0-238F-46AF-ADB4-6C85480369C7}"));
                    stTemp          = PathToDirectory;
                    strSpiderBin    = PathToDirectory.Replace("Documents", "Saved Games\\Microsoft Games\\Spider Solitaire\\Spider Solitaire.SpiderSolitaireSave-ms");
                    PathToResult    = stTemp.Replace("Documents", strResultName);
                    bIsThere        = File.Exists(strSpiderBin);
                    if (!bIsThere)
                    {
                        string strEXE;
                        Console.WriteLine("nothing here also " + strSpiderBin + "\n");
                        Console.WriteLine("Trying local directory where this .exe program resides\n");
                        strEXE          = System.Reflection.Assembly.GetEntryAssembly().Location;
                        PathToDirectory = System.IO.Path.GetDirectoryName(strSpiderBin0);
                        Console.WriteLine("Looking here: " + PathToDirectory + "\n");
                        strSpiderBin0 = PathToDirectory + "\\Spider Solitaire.SpiderSolitaireSave-ms";
                        if (!File.Exists(strSpiderBin0))
                        {
                            Console.WriteLine("Giving up, cannot find " + strSpiderBin0);
                            Console.ReadLine();
                            Environment.Exit(0);
                        }
                        else
                        {
                            strSpiderBin = strSpiderBin0;
                        }
                    }
                    else
                    {
                        strSpiderBin0 = strSpiderBin;
                    }
                }
                else
                {
                    strSpiderBin0 = strSpiderBin;
                }
            }
            else
            {
                strSpiderBin = strSpiderBin0;
            }
            PathToDirectory = Path.GetDirectoryName(strSpiderBin) + "\\";

            Directory.CreateDirectory(PathToResult);    // create 2018 if not exist
            while (true)
            {
                iDirNum++;
                stTemp   = PathToResult + "\\" + iDirNum.ToString();
                bIsThere = Directory.Exists(stTemp);
                if (bIsThere)
                {
                    continue;
                }
                bIsThere = Directory.Exists(stTemp + "-L");
                if (bIsThere)
                {
                    continue;
                }
                break;
            }

            Console.WriteLine("enter W- for win or L- for loss plus any comment\n");
            Console.WriteLine("enter R to rename or enter A to add text when renaming\n");
            Console.WriteLine("enter F for first or 0..5 for seeds and G for original\n");
            Console.WriteLine("  example:  R S2C1    A -0f-   A -2SEED-\n");
            string strReply   = Console.ReadLine();
            string strSuffix  = strReply.Substring(0, 1).ToLower();
            string strLRename = "f012345g";

            string[] strLs = { "first", "0seed", "1seed", "2seed", "3seed", "4seed", "5seed", "ORIGINAL" };
            int      iCmd  = strLRename.IndexOf(strSuffix);

            if (iCmd >= 0)
            {
                strName = "Spider Solitaire.SpiderSolitaireSave-ms";
                strFrom = PathToDirectory + strName;
                if (File.Exists(strFrom))
                {
                    string strPathTo = strFrom;
                    string strTo     = strLs[iCmd];
                    strName = "Spider Solitaire" + "-" + strTo + "-.";

                    System.IO.File.Move(strFrom, strPathTo.Replace("Spider Solitaire.", strName));
                    Environment.Exit(0);
                }
            }

            if (strSuffix == "r" || strSuffix == "a")
            {
                strName = "Spider Solitaire.SpiderSolitaireSave-ms";
                strFrom = PathToDirectory + strName;
                if (File.Exists(strFrom))
                {
                    string strPathTo = strFrom;
                    string strTo     = strReply.Substring(1) + ".";
                    if (strSuffix.ToLower() == "a")
                    {
                        strName = "Spider Solitaire" + strTo.Trim();
                    }
                    else
                    {
                        strName = strTo.Trim();
                    }

                    System.IO.File.Move(strFrom, strPathTo.Replace("Spider Solitaire.", strName));
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine("cannot find save file\n");
                    Console.ReadLine();
                    Environment.Exit(0);
                }
            }
            strSuffix = "";
            if (strReply.Substring(0, 1).ToLower() == "l")
            {
                strSuffix = "-L";
            }
            else
            {
                // no other commands other than L or W
                if (strReply.Substring(0, 1).ToLower() != "w")
                {
                    Console.WriteLine("Invalid command, try again\n");
                    Console.ReadLine();
                    Environment.Exit(0);
                }
            }
            ClearDir(PathToDirectory);
            stTemp += strSuffix;
            Directory.CreateDirectory(stTemp);
            foreach (string sFile in Directory.GetFiles(PathToDirectory, "*.SpiderSolitaireSave-ms"))
            {
                if (Path.GetFileName(sFile) == "Spider Solitaire.SpiderSolitaireSave-ms" && strSuffix == "")
                {
                    continue;
                }
                dFile = stTemp + "\\" + Path.GetFileName(sFile);
                System.IO.File.Move(sFile, dFile);
            }
            if (strReply != "")
            {
                dFile = stTemp + "\\notes.txt";
                System.IO.File.WriteAllText(dFile, strReply);
            }
            // need to create a new spider game
            // no simple way since program could be anywhere
        }
Exemplo n.º 2
0
        public static List <RunItem> AddWindows10AppsBetterWay()
        {
            var win10AppList = AddWindows10Apps();

            var list = new List <RunItem>();

            using (PowerShell PowerShellInstance = PowerShell.Create())
            {
                // use "AddScript" to add the contents of a script file to the end of the execution pipeline.
                // use "AddCommand" to add individual commands/cmdlets to the end of the execution pipeline.
                PowerShellInstance.AddScript("Get-StartApps");

                // invoke execution on the pipeline (collecting output)
                Collection <PSObject> PSOutput = PowerShellInstance.Invoke();
                // use "AddParameter" to add a single parameter to the last command/script on the pipeline.
                //PowerShellInstance.AddParameter("param1", "parameter 1 value!");

                var dirs = Directory.GetDirectories("C:\\Program Files\\WindowsApps");
                foreach (PSObject outputItem in PSOutput)
                {
                    //TODO: handle/process the output items if required
                    var item = outputItem.ToString();
                    try
                    {
                        var runItem = new RunItem()
                        {
                            Type = ItemType.Win10App
                        };

                        var split = item.Split('=');
                        var name  = split[1].Split(';')[0];
                        var appID = split[2].Substring(0, split[2].Length - 1);
                        runItem.Command = appID;
                        runItem.Name    = name;
                        var uri   = appID;
                        int count = uri.Count(f => f == '{');

                        if (count > 0)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var    startIndex  = uri.IndexOf("{", StringComparison.Ordinal);
                                var    endIndex    = uri.IndexOf("}", StringComparison.Ordinal);
                                string guids       = uri.Substring(startIndex + 1, endIndex - startIndex - 1);
                                var    guid        = new Guid(guids);
                                var    knownFolder = KnownFolderFinder.GetFolderFromKnownFolderGUID(guid);
                                if (knownFolder != null)
                                {
                                    uri = uri.Replace($"{{{guids}}}", knownFolder);
                                }
                            }
                        }

                        runItem.URI = uri;
                        if (!File.Exists(runItem.URI))
                        {
                            runItem.URI = "Win 10 app";
                        }


                        //propertyInfo = item.GetType().GetProperty("InstallLocation");
                        //var installLocation = (string)propertyInfo.GetValue(item, null);
                        //var icon = GetWin10Icon(installLocation + "\\AppxManifest.xml");


                        try
                        {
                            var hit = win10AppList.FirstOrDefault(p => p.Command.Contains(uri.Split('!')[0]));
                            if (hit != null)
                            {
                                runItem.IconName       = hit.IconName;
                                runItem.IconBackGround = hit.IconBackGround;
                                runItem.KeyWords.Add(hit.Name);
                                win10AppList.Remove(hit);
                            }
                        }
                        catch (Exception)
                        {
                            Log.Error("Could not att win 10 icon.");
                        }


                        list.Add(runItem);
                    }
                    catch (Exception)
                    {
                        Log.Error($"Could not add win 10 app {item}");
                    }
                }
            }
            list.AddRange(win10AppList);

            return(list);
        }