Exemple #1
0
        public void Execute_PathToDirectory_Valid(string value, string expected)
        {
            var function = new PathToDirectory(string.Empty);
            var result   = function.Evaluate(value);

            Assert.That(result, Is.EqualTo(expected));
        }
        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
        }
Exemple #3
0
        static void Main(string[] args)
        {
            bool   bIsThere      = false;
            string strSpiderBin0 = "";
            string PathToDirectory;
            string stTemp = System.Reflection.Assembly.GetEntryAssembly().Location; // path to executable

            // KnownFolderFinder.EnumerateKnownFolders();   // this was used for testing purposes
            // GlobalClass.InitExceptions();

            // if argument is supplied and extension is a saved game, then use that
            GlobalClass.bLookForFirstColumn = true;
            GlobalClass.bFoundFirstColunn   = false;
            Console.WriteLine("Spider(v) 1.0; 5-20-2018; Copyright Joseph Stateson:  [email protected]\n");

            if (args.Count() > 0)
            {
                if (args[0].Contains(".SpiderSolitaireSave-ms"))
                {
                    string path = Directory.GetCurrentDirectory();
                    strSpiderBin0 = path + "\\" + args[0];
                    bIsThere      = File.Exists(strSpiderBin0);
                    Debug.Assert(bIsThere);
                    GlobalClass.strSpiderBin = strSpiderBin0;
                }
            }
            else
            {
                // look for file in current director and use that one
                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
                GlobalClass.strSpiderBin = strSpiderBin0.Replace("Documents", "Saved Games\\Microsoft Games\\Spider Solitaire\\Spider Solitaire.SpiderSolitaireSave-ms");
                bIsThere = File.Exists(GlobalClass.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
                    Console.WriteLine("could not find " + GlobalClass.strSpiderBin + "\n");
                    PathToDirectory          = KnownFolderFinder.GetFolderFromKnownFolderGUID(new Guid("{FDD39AD0-238F-46AF-ADB4-6C85480369C7}"));
                    GlobalClass.strSpiderBin = PathToDirectory.Replace("Documents", "Saved Games\\Microsoft Games\\Spider Solitaire\\Spider Solitaire.SpiderSolitaireSave-ms");
                    bIsThere = File.Exists(GlobalClass.strSpiderBin);
                    if (!bIsThere)
                    {
                        string strEXE;
                        Console.WriteLine("nothing here also " + GlobalClass.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);
                            Environment.Exit(0);
                        }
                        else
                        {
                            GlobalClass.strSpiderBin = strSpiderBin0;
                        }
                    }
                    else
                    {
                        strSpiderBin0 = GlobalClass.strSpiderBin;
                    }
                }
                else
                {
                    strSpiderBin0 = GlobalClass.strSpiderBin;
                }
            }
            else
            {
                GlobalClass.strSpiderBin = strSpiderBin0;
            }
            PathToDirectory = Path.GetDirectoryName(GlobalClass.strSpiderBin) + "\\";
            GlobalClass.strSpiderOutputBinary = GlobalClass.strSpiderBin = strSpiderBin0;
            GlobalClass.strSpiderDir          = PathToDirectory;
            GlobalClass.strSpiderName         = PathToDirectory + Path.GetFileNameWithoutExtension(strSpiderBin0);
            GlobalClass.strSpiderExt          = Path.GetExtension(strSpiderBin0);
            ClearDir(PathToDirectory);  // erases files with pattern DEAL*, SUIT*, *.mov and adeck and those xml ones also
            cSpinControl cSC = new cSpinControl();

            DisAssemble    = new cDisassemble(ref cSC);
            Suitable       = new csuitable(ref cSC, ref DisAssemble);
            Strategy       = new cStrategy(ref cSC, ref DisAssemble);
            Reduce         = new cReduce(ref cSC, ref DisAssemble, ref Strategy);
            cSC.Strategy   = Strategy;
            cSC.Suitable   = Suitable;
            cSC.JoinSuited = new cJoinSuited(ref cSC);

            Test = new cTest(ref cSC, ref Strategy);

//            Test.RunTest();

            // http://stackoverflow.com/questions/177856/how-do-i-trap-ctrl-c-in-a-c-sharp-console-apphttp://stackoverflow.com/questions/177856/how-do-i-trap-ctrl-c-in-a-c-sharp-console-app
            try
            {
                SolveBoard(ref cSC, GlobalClass.strSpiderBin);
            }
            catch (Exception e)
            {
                if (e.Message != "Spider")
                {
                    throw e;
                }
                //GlobalClass.eExceptionType eID = (GlobalClass.eExceptionType) e.Data["ID"];
                string msg = (string)e.Data["MSG"];
                Console.WriteLine(msg);
                Environment.Exit(0);
            }
        }