示例#1
0
        public static void XlsxToCSV()
        {
            string xlsxpath   = Application.dataPath + "/XLSX";
            string streampath = Application.dataPath + "/StreamingAssets";
            string csvpath    = Application.dataPath + "/StreamingAssets/csv";

            _csvListToBeRestored.Clear();
            //文件列表
            //string listpath = Application.dataPath + "/StreamingAssets/csvList.txt";
            //FileStream fs = new FileStream( listpath, FileMode.Create );
            //StreamWriter listwriter = new StreamWriter( fs, new UTF8Encoding(false) );
            DirectoryInfo TheFolder = new DirectoryInfo(xlsxpath);

            if (!Directory.Exists(csvpath))
            {
                Directory.CreateDirectory(csvpath);
            }

            try
            {
                //对文件进行遍历
                foreach (var NextFile in TheFolder.GetFiles())
                {
                    if (Path.GetExtension(NextFile.Name) == ".xlsx" && !NextFile.Name.StartsWith("~$"))
                    {
                        string csvfile = XLSXTOCSV(NextFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
                        CreateCSVFile(csvpath + "/" + NextFile.Name.Split('.')[0] + ".csv", csvfile);
                        Debug.Log(NextFile.Name.Split('.')[0] + "  文件生成成功!");
                        //listwriter.WriteLine( "csv/" + NextFile.Name.Split( '.' )[ 0 ] + ".csv" );
                        string str = "csv/" + NextFile.Name.Split('.')[0] + ".csv";
                        _csvListToBeRestored.Add(new ABVersion {
                            AbName = str, MD5 = LitFramework.Crypto.Crypto.md5.GetFileHash(csvpath + "/" + NextFile.Name.Split('.')[0] + ".csv"), Version = 1
                        });
                    }
                    else if (Path.GetExtension(NextFile.Name) == ".txt")
                    {
                        FileInfo fi = new FileInfo(csvpath + "/" + NextFile.Name);
                        if (fi.Exists)
                        {
                            fi.Delete();
                        }
                        NextFile.CopyTo(csvpath + "/" + NextFile.Name);
                        //listwriter.WriteLine( NextFile.Name );
                        _csvListToBeRestored.Add(new ABVersion {
                            AbName = NextFile.Name, MD5 = string.Empty, Version = 0
                        });
                    }
                }

                //遍历框架配置的额外后缀文件
                string[] extralFile = FrameworkConfig.Instance.configs_suffix.Split('|');
                foreach (var item in extralFile)
                {
                    if (item.Equals("csv"))
                    {
                        continue;
                    }

                    GetFiles(new DirectoryInfo(streampath), item, _csvListToBeRestored);
                }
            }
            catch (Exception e) { Debug.LogError(e.Message); }
            finally
            {
                //加载本地文件,没有就创建完成。有则比对同名文件的MD5,不一样则version+1
                MatchCSVTotalFile(_csvListToBeRestored);

                //listwriter.Close();
                //listwriter.Dispose();
                //fs.Dispose();
#if UNITY_EDITOR
                AssetDatabase.Refresh();
#endif
            }
        }
示例#2
0
        /// <summary>
        /// 复制聚焦壁纸
        /// </summary>
        /// <returns></returns>
        private void copyWallpaper(Boolean isChangeWall)
        {
            new Thread(new ThreadStart(() => {
                string savePath = "";
                Dispatcher.Invoke(new Action(delegate
                {
                    savePath = this.savePathBox.Text;
                }));
                if (savePath.Equals(""))
                {
                    return;
                }

                Dispatcher.Invoke(new Action(delegate
                {
                    this.synBut.Content   = "同步中";
                    this.synBut.IsEnabled = false;
                }));

                // 目录不存在则创建
                if (!Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(savePath);
                }

                //聚焦壁纸保存目录
                string path = Environment.GetEnvironmentVariable("LOCALAPPDATA") + "\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets";

                //要更换的壁纸名称
                string wallName = "";

                DirectoryInfo TheFolder = new DirectoryInfo(path);
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    string newName = NextFile.Name;

                    // 设置壁纸扩展名 横版为jpg 竖版为jpeg
                    Image image = Image.FromFile(path + "\\" + newName);
                    if (image.Width > image.Height)
                    {
                        newName += ".jpg";
                    }
                    else
                    {
                        newName += ".jpeg";
                    }

                    // 大于200KB的保存
                    string newFile = savePath + "\\" + newName;
                    if (NextFile.Length / 1024 > 200)
                    {
                        if (!File.Exists(newFile))
                        {
                            NextFile.CopyTo(newFile);

                            if (image.Width > image.Height)
                            {
                                wallName = newName;
                            }
                        }
                    }
                }

                Dispatcher.Invoke(new Action(delegate
                {
                    this.synBut.Content   = "立即同步";
                    this.synBut.IsEnabled = true;
                }));

                // 同步后切换最新壁纸
                if ((Boolean)isChangeWall)
                {
                    Dispatcher.Invoke(new Action(delegate
                    {
                        this.changeWallpaperByName(wallName);
                    }));
                }

                // 显示图片预览
                Dispatcher.Invoke(new Action(delegate
                {
                    if (this.WindowState != System.Windows.WindowState.Minimized)
                    {
                        this.showImages();
                    }
                }));

                GC.Collect();
            })).Start();
        }
示例#3
0
        public static void CsvToCs()
        {
            Debug.Log("配置文件转化为代码  开始!");
            _csvListToBeRestored.Clear();
            string xlsxpath   = Application.dataPath + "/XLSX";
            string streampath = Application.dataPath + "/StreamingAssets";
            string csvOutPath = Application.dataPath + "/StreamingAssets/csv";
            string csOutPath  = Application.dataPath + "/Scripts/CSV";

            if (!FrameworkConfig.Instance.UseHotFixMode)
            {
                csOutPath = Application.dataPath + "/Scripts/CSV";
            }
            else
            {
                csOutPath = Application.dataPath + "/Scripts/ILRuntime/HotFixLogic/CSV";
            }
            DirectoryInfo theXMLFolder = new DirectoryInfo(xlsxpath);

            //文件列表
            //string listpath = Application.dataPath + "/StreamingAssets/csvList.txt";
            //FileStream fs = new FileStream( listpath, FileMode.Create );
            //StreamWriter listwriter = new StreamWriter( fs, new UTF8Encoding(false) );

            if (!Directory.Exists(csvOutPath))
            {
                Directory.CreateDirectory(csvOutPath);
            }
            if (!Directory.Exists(csOutPath))
            {
                Directory.CreateDirectory(csOutPath);
            }

            try
            {
                ConfigsNamesTemplate cnt = new ConfigsNamesTemplate();
                //对文件进行遍历
                foreach (var NextFile in theXMLFolder.GetFiles())
                {
                    if (Path.GetExtension(NextFile.Name) == ".xlsx" && !NextFile.Name.StartsWith("~$"))
                    {
                        LDebug.Log(" >表处理 : " + NextFile.Name);
                        FileStream stream  = NextFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        string     csvfile = XLSXTOCSV(stream);
                        CSVParser  cp      = new CSVParser();
                        CreateCSFile(csOutPath, NextFile.Name.Split('.')[0] + ".cs", cp.CreateCS(NextFile.Name.Split('.')[0], csvfile));
                        CreateCSVFile(csvOutPath + "/" + NextFile.Name.Split('.')[0] + ".csv", csvfile);
                        LDebug.Log(NextFile.Name.Split('.')[0] + "  文件生成成功!");

                        //这里固定取配置表第三行配置作为类型读取,如果需要修改配置表适配服务器(增加第四行),需要同步修改
                        CSVReader reader = new CSVReader(csvfile);
                        cnt.configsNameList.Add(NextFile.Name.Split('.')[0], reader.GetData(0, 2));
                        //listwriter.WriteLine( "csv/" + NextFile.Name.Split( '.' )[ 0 ] + ".csv" );
                        string str = "csv/" + NextFile.Name.Split('.')[0] + ".csv";
                        _csvListToBeRestored.Add(new ABVersion {
                            AbName = str, MD5 = LitFramework.Crypto.Crypto.md5.GetFileHash(csvOutPath + "/" + NextFile.Name.Split('.')[0] + ".csv"), Version = 1
                        });
                    }
                    else if (Path.GetExtension(NextFile.Name) == ".txt")
                    {
                        FileInfo fi = new FileInfo(csvOutPath + "/" + NextFile.Name);
                        if (fi.Exists)
                        {
                            fi.Delete();
                        }
                        NextFile.CopyTo(csvOutPath + "/" + NextFile.Name);
                        //listwriter.WriteLine( NextFile.Name );
                        _csvListToBeRestored.Add(new ABVersion {
                            AbName = NextFile.Name, MD5 = string.Empty, Version = 0
                        });
                    }
                }

                //遍历框架配置的额外后缀文件
                string[] extralFile = FrameworkConfig.Instance.configs_suffix.Split('|');
                foreach (var item in extralFile)
                {
                    if (item.Equals("csv"))
                    {
                        continue;
                    }

                    GetFiles(new DirectoryInfo(streampath), item, _csvListToBeRestored);
                }

                //============更新并保存CS============//
                ConfigsParse rpp = new ConfigsParse();

                if (!FrameworkConfig.Instance.UseHotFixMode)
                {
                    EditorMenuExtention.CreateCSFile(Application.dataPath + "/Scripts/Model/Const/", "Configs.cs", rpp.CreateCS(cnt));
                }
                else
                {
                    EditorMenuExtention.CreateCSFile(Application.dataPath + "/Scripts/ILRuntime/HotFixLogic/Model/Const/", "Configs.cs", rpp.CreateCS(cnt));
                }
            }
            catch (Exception e) { LDebug.LogError(e.Message); }
            finally
            {
                //加载本地文件,没有就创建完成。有则比对同名文件的MD5,不一样则version+1
                MatchCSVTotalFile(_csvListToBeRestored);

                //listwriter.Close();
                //listwriter.Dispose();
                //fs.Dispose();
#if UNITY_EDITOR
                AssetDatabase.Refresh();
#endif
            }
        }