Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FetchOriginalGames.cs « Tasks « Tooling - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: abd514d073ed90dfb9a0230568764589c7d6b564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.clusterrr.hakchi_gui.Tooling.Tasks
{
    class FetchOriginalGames:TaskableTool
    {
        clovershell.ClovershellConnection theConnection;
        clovershell.ClovershellWrapper wrapper;
        public FetchOriginalGames(clovershell.ClovershellConnection conn):base("Fetching orignal games")
        {
            wrapper = new clovershell.ClovershellWrapper(conn);
        }
        public override void Execute()
        {
           
            ReportProgress(0);
            try
            {
                ReportStatus("Unmounting current filesystem");
                try
                {
                    wrapper.ExecuteConsoleCommand("umount /usr/share/games/nes/kachikachi/");
                }
                catch(Exception exc)
                {
                    //Will fail if already unmounted so not much issue here.
                }
                ReportStatus("Fetching game listing from NES Classic");
                clovershell.ClovershellWrapper.FolderDetail folders= wrapper.GetFolderDetail("/usr/share/games/nes/kachikachi/");
                for(int x = 0;x<folders.Folders.Count;x++)
                {
                    ReportStatus("Fetching " + folders.Folders[x]);
                    clovershell.ClovershellWrapper.FolderDetail gamefolder = wrapper.GetFolderDetail("/usr/share/games/nes/kachikachi/" + folders.Folders[x] +"/");
                    foreach(string f in gamefolder.Files)
                    {
                        string localPath = System.IO.Path.Combine(NesMiniApplication.GamesDirectory, folders.Folders[x]+"\\"+ f);
                        if(localPath.Contains("\\PRODUCTION-TESTS\\"))
                        {
                            localPath = localPath.Replace("\\PRODUCTION-TESTS\\", "\\CLV-P-AAAAA\\");
                        }
                        if(localPath.Contains("\\PRODUCTION-TESTS.desktop"))
                        {
                            localPath = localPath.Replace("\\PRODUCTION-TESTS.desktop", "\\CLV-P-AAAAA.desktop");
                        }
                        if(System.IO.File.Exists(localPath))
                        {
                            System.IO.File.Delete(localPath);
                        }
                        if(!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(localPath)))
                        {
                            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(localPath));
                        }
                        System.IO.File.WriteAllBytes(localPath, wrapper.GetFile("/usr/share/games/nes/kachikachi/" + folders.Folders[x] + "/" + f));
                    }
                    ReportProgress(((x + 1) * 100) / folders.Folders.Count);
                    Console.Write("");
                }
                ReportStatus("Rebooting");
                wrapper.Reboot();
                ReportStatus("Reloading games");
                Manager.GameManager.GetInstance().LoadLibrary();
                ReportCompleted();

            }
            catch(Exception exc)
            {
                ReportStatus("Rebooting");
                wrapper.Reboot();
                ReportError(exc.Message, true);
            }

        
        }
    }
}